We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 30990e3 commit c6aee05Copy full SHA for c6aee05
132-palindrome-partitioning-ii.js
@@ -2,6 +2,37 @@
2
* @param {string} s
3
* @return {number}
4
*/
5
+
6
+const minCut = function(s) {
7
+ const n = s.length
8
+ if (n <= 1) return 0
9
+ const dp = new Array(n).fill(0)
10
+ for (let i = 1; i < n; i++) dp[i] = i
11
+ for (let i = 1; i < n; i++) {
12
+ // odd
13
+ for (
14
+ let start = i, end = i;
15
+ end < n && start >= 0 && s[end] === s[start];
16
+ start--, end++
17
+ ) {
18
+ dp[end] = Math.min(dp[end], start === 0 ? 0 : dp[start - 1] + 1)
19
+ }
20
+ // even
21
22
+ let start = i - 1, end = i;
23
24
25
26
27
28
29
+ return dp[n - 1]
30
+}
31
32
33
34
+// another
35
36
const minCut = function(s) {
37
const n = s.length
38
const cut = new Array(n + 1).fill(0)
0 commit comments