Skip to content

Commit e6272b7

Browse files
authoredMar 28, 2022
Create 131-Palindrome-Partitioning.py
1 parent 5cc5751 commit e6272b7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
 

‎131-Palindrome-Partitioning.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def partition(self, s: str) -> List[List[str]]:
3+
res, part = [], []
4+
5+
def dfs(i):
6+
if i >= len(s):
7+
res.append(part.copy())
8+
return
9+
for j in range(i, len(s)):
10+
if self.isPali(s, i, j):
11+
part.append(s[i:j+1])
12+
dfs(j + 1)
13+
part.pop()
14+
dfs(0)
15+
return res
16+
17+
def isPali(self, s, l, r):
18+
while l < r:
19+
if s[l] != s[r]:
20+
return False
21+
l, r = l + 1, r - 1
22+
return True

0 commit comments

Comments
 (0)
Please sign in to comment.