Skip to content

Commit 8e79f35

Browse files
authored
Create L132.go
1 parent 72984d7 commit 8e79f35

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Hard/L132.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package Hard
2+
3+
func minCut(s string) int {
4+
cut, n := make([]int, len(s)), len(s)
5+
pal := make([][]bool, n*n)
6+
for i := 0; i < n; i++ {
7+
pal[i] = make([]bool, n)
8+
}
9+
10+
for i := 0; i < n; i++ {
11+
min := i
12+
for j := 0; j <= i; j++ {
13+
if s[j] == s[i] && (j+1 > i-1 || pal[j+1][i-1]) {
14+
pal[j][i] = true
15+
if j == 0 {
16+
min = 0
17+
} else {
18+
if cut[j-1]+1 < min {
19+
min = cut[j-1] + 1
20+
}
21+
}
22+
}
23+
}
24+
cut[i] = min
25+
}
26+
27+
return cut[n-1]
28+
}

0 commit comments

Comments
 (0)