Solution to LeetCode 1332 Remove Palindromic Subsequences.
LeetCode 1332
Remove Palindromic Subsequences (Easy). [link]
A string is a subsequence of a given string if it is generated by deleting some characters of a given string without changing its order. Note that a subsequence does not necessarily need to be contiguous. A string is called palindrome if is one that reads the same backward as well as forward.
The most times of deleting is 2. So the problem is the same as determining whether the string is a palindrome or not. If yes, return 1, otherwise return 2.
class Solution(object):
def removePalindromeSub(self, s):
"""
:type s: str
:rtype: int
"""
return 1 if s == s[::-1] else 2
LeetCode 1246 (VIP) is the hard version.