Skip to content

Commit 41f2c25

Browse files
authored
feat: add js solution lc 0664
1 parent dfae561 commit 41f2c25

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var strangePrinter = function(s) {
6+
const n = s.length;
7+
const f = new Array(n).fill(0).map(() => new Array(n).fill(1 << 30));
8+
for (let i = n - 1; i >= 0; --i) {
9+
f[i][i] = 1;
10+
for (let j = i + 1; j < n; ++j) {
11+
if (s[i] === s[j]) {
12+
f[i][j] = f[i][j - 1];
13+
} else {
14+
for (let k = i; k < j; ++k) {
15+
f[i][j] = Math.min(f[i][j], f[i][k] + f[k + 1][j]);
16+
}
17+
}
18+
}
19+
}
20+
return f[0][n - 1];
21+
};

0 commit comments

Comments
 (0)