Skip to content

Commit 2249138

Browse files
authored
Update 1745-palindrome-partitioning-iv.js
1 parent e41f6a8 commit 2249138

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

1745-palindrome-partitioning-iv.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,31 @@ function manacher(s) {
4747
return ans;
4848
}
4949

50+
// another
51+
52+
/**
53+
* @param {string} s
54+
* @return {boolean}
55+
*/
56+
const checkPartitioning = function (s) {
57+
const n = s.length
58+
const dp = Array.from({ length: n }, () => Array(n).fill(false))
59+
for(let i = n - 1; i >= 0; i--) {
60+
for(let j = i; j < n; j++) {
61+
if(s[i] === s[j]) {
62+
dp[i][j] = i + 1 <= j - 1 ? dp[i + 1][j - 1] : true
63+
} else dp[i][j] = false
64+
}
65+
}
66+
for(let i = 1; i < n - 1; i++) {
67+
for(let j = i; j < n - 1; j++) {
68+
if(dp[0][i - 1] && dp[i][j] && dp[j + 1][n - 1]) return true
69+
}
70+
}
71+
return false
72+
}
73+
74+
5075
// another
5176

5277
/**

0 commit comments

Comments
 (0)