We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 4532559 + 5cb33f7 commit 2ef92a2Copy full SHA for 2ef92a2
go/131-Palindrome-Partitioning.go
@@ -0,0 +1,34 @@
1
+package main
2
+
3
+func partition(s string) [][]string {
4
+ ans := make([][]string, 0)
5
+ curr := make([]string, 0)
6
+ var backtrack func(idx int)
7
+ backtrack = func(idx int) {
8
+ if idx == len(s) {
9
+ ans = append(ans, append([]string{}, curr...))
10
+ }
11
+ for i := idx; i < len(s); i++ {
12
+ if isPalindrome(s[idx : i+1]) {
13
+ curr = append(curr, s[idx:i+1])
14
+ backtrack(i + 1)
15
+ curr = curr[:len(curr)-1]
16
17
18
19
+ backtrack(0)
20
+ return ans
21
+}
22
23
+func isPalindrome(s string) bool {
24
+ l := 0
25
+ r := len(s) - 1
26
+ for l < r {
27
+ if s[l] != s[r] {
28
+ return false
29
30
+ l++
31
+ r--
32
33
+ return true
34
0 commit comments