Skip to content

1332. Remove Palindromic Subsequences 👎

  • Time: $O(n)$
  • Space: $O(1)$
1
2
3
4
5
6
class Solution {
 public:
  int removePalindromeSub(string s) {
    return equal(s.begin(), s.end(), s.rbegin()) ? 1 : 2;
  }
};
1
2
3
4
5
class Solution {
  public int removePalindromeSub(String s) {
    return s.equals(new StringBuilder(s).reverse().toString()) ? 1 : 2;
  }
}
1
2
3
class Solution:
  def removePalindromeSub(self, s: str) -> int:
    return 1 if s == s[::-1] else 2