Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f3a6af

Browse files
authored
Create 0131-palindrome-partitioning.kt
1 parent20a62bf commit9f3a6af

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
classSolution {
2+
funpartition(s:String):List<List<String>> {
3+
val res= mutableListOf<MutableList<String>>()
4+
val part= mutableListOf<String>()
5+
6+
funisPalindrome(_l:Int,_r:Int):Boolean {
7+
var l=_l
8+
var r=_r
9+
while (l< r) {
10+
if (s[l]!= s[r])
11+
returnfalse
12+
l++
13+
r--
14+
}
15+
returntrue
16+
}
17+
18+
fundfs(i:Int) {
19+
if (i>= s.length) {
20+
res.add(part.toMutableList())
21+
return
22+
}
23+
24+
for (jin i until s.length) {
25+
if (isPalindrome(i, j)) {
26+
part.add(s.substring(i, j+1))
27+
dfs(j+1)
28+
part.removeAt(part.lastIndex)
29+
}
30+
}
31+
}
32+
33+
dfs(0)
34+
return res
35+
}
36+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp