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.
1 parent 72984d7 commit 8e79f35Copy full SHA for 8e79f35
Hard/L132.go
@@ -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
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