1332. Remove Palindromic Subsequences
Last updated
Last updated
/**
* Time complexity : O(n)
* Space complexity : O(1)
*/
class Solution {
public int removePalindromeSub(String s) {
if(s.isEmpty()) {
return 0;
}
return isPalindrome(s)? 1: 2;
}
private boolean isPalindrome(String s) {
int left = 0, right = s.length()-1;
while(left < right) {
if(s.charAt(left) != s.charAt(right)) {
return false;
}
left++;
right--;
}
return true;
}
}