Yêu em Thu Nga CN12 ptit
Senior Member
Mới sáng mở mắt ra đớp được bài hard dễ vl, phần palindrome đúng kiểu cứ ốp qhđ là ra, được mấy bài hard phần này rồi, dạng cứ na ná nhau
https://leetcode.com/problems/palindrome-partitioning-iv/
https://leetcode.com/problems/palindrome-partitioning-iv/
C++:
class Solution {
public:
bool checkPartitioning(string s) {
if(s.length()<3) return false;
vector<vector<bool>>dp(s.length(),vector<bool>(s.length(),false));
for(int i=0;i<s.length();i++) dp[i][i]=true;
for(int i=s.length()-2;i>=0;i--){
for(int j=i+1;j<s.length();j++){
if((s[i]==s[j])&&(j-i<2||dp[i+1][j-1])) dp[i][j]=true;
}
}
for(int i=1;i<s.length();i++){
for(int j=i;j<s.length()-1;j++){
if(dp[0][i-1]&&dp[i][j]&&dp[j+1][s.length()-1]) return true;
}
}
return false;
}
};