Skip to main content

1332 - Remove Palindromic Subsequences

Details

KeyValue
Linkhttps://leetcode.com/problems/remove-palindromic-subsequences/
LanguagePython 3
Runtime35 ms, faster than 68.78% of Python3 online submissions for Remove Palindromic Subsequences
Memory Usage13.8 MB, less than 53.87% of Python3 online submissions for Remove Palindromic Subsequences
DatastructuresString
AlgorithmsReverse string

Procedure

  1. TBD...

Code

Option 1

class Solution:
def removePalindromeSub(self, s: str) -> int:
# Don't confuse subarry with subsequence.
# Subarrays are consecutive.
# Subsequence don't have to be consecutive.

if not s: return 0 # Empty String
if s == s[::-1]: return 1 # Palindrome
return 2

Option 2: One-Liner

class Solution:
def removePalindromeSub(self, s: str) -> int:
return 1 if s == s[::-1] else 2