Leetcode Weekly Contest 319 | Maximum Number of Non-overlapping Palindrome Substrings | Analysis

preview_player
Показать описание
Analysis of "Maximum Number of Non-overlapping Palindrome Substrings" Problem from Leetcode Weekly Contest 319.
Join Programming Community!!

For Collaboration and Promotion:-

Contact me here:-
Рекомендации по теме
Комментарии
Автор

I dont know why I am getting an error for somewhat similar code: One of the testcases I failed: 
"iqqibcecvrbxxj"
1

Can you help me out? I know that I am not optimizing the isPalindrome function. But y is this test case failing?


class Solution {
public int maxPalindromes(String s, int k) {
int[] dp =new int[s.length()];
Arrays.fill(dp, -1);
int a=check(dp, 0, s, k);
return a;
}
public int check(int[] dp, int i, String s, int k){
if(i==s.length()){
return 0;
}
if(i>s.length()){
return (int)(-1e9);
}
if(dp[i]!=-1){
return dp[i];
}

int a=(int)(-1e9);
for(int j=i;j<s.length();j++){
if(j-i+1>=k && (isPalindrome(s.substring(i, j+1))==true)){
a=1+check(dp, j+1, s, k);
}
}
int b =check(dp, i+1, s, k);
return dp[i]=Math.max(a, b);
}
public boolean isPalindrome(String s){
int st =0, e =s.length()-1;

while(st<e){

return false;
}
st++;
e--;
}

return true;
}
}

notsodope
join shbcf.ru