131. Palindrome Partitioning
Solution:
class Solution:
def validpalindrome(self, s):
if len(s) == 1:
return True
lo, hi = 0, len(s)-1
while lo < hi:
if s[lo] != s[hi]:
return False
lo += 1
hi -= 1
return True
def partition(self, s: str) -> List[List[str]]:
if not s:
return []
res = []
for i in range(1, len(s)+1):
if self.validpalindrome(s[:i]):
temp = self.partition(s[i:])
if temp:
for j in range(len(temp)):
res.append([s[:i]]+temp[j])
else:
res.append([s[:i]])
return res