Skip to content

Commit 61eff30

Browse files
committed
688ms, 50%, 80%.
1 parent edb5450 commit 61eff30

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

131.palindrome-partitioning.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# @lc app=leetcode id=131 lang=python3
3+
#
4+
# [131] Palindrome Partitioning
5+
#
6+
7+
# @lc code=start
8+
9+
class Solution:
10+
def partition(self, s: str) -> List[List[str]]:
11+
res = []
12+
self.dfs(s, [], res)
13+
return res
14+
15+
def dfs(self, s, path, res):
16+
# if s is empty
17+
if not s:
18+
res.append(path)
19+
return
20+
21+
for i in range(1, len(s)+1):
22+
if self.isPal(s[:i]):
23+
self.dfs(s[i:], path+[s[:i]], res)
24+
25+
def isPal(self, s):
26+
# s is equal to reversed s
27+
return s == s[::-1]
28+
29+
30+
# @lc code=end

0 commit comments

Comments
 (0)