Skip to content

Commit d32dda5

Browse files
authored
Create 1745-palindrome-partitioning-iv.js
1 parent 574716a commit d32dda5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

1745-palindrome-partitioning-iv.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
const checkPartitioning = function(s) {
6+
for(let i = 1, len = s.length; i < len - 1; i++) {
7+
for(let j = i + 1; j < len; j++) {
8+
const s1 = s.slice(0, i), s2 = s.slice(i, j), s3 = s.slice(j)
9+
if(chk(s1) && chk(s2) && chk(s3)) return true
10+
}
11+
}
12+
return false
13+
};
14+
15+
function chk(s) {
16+
let l = 0, r = s.length - 1
17+
for(;l <= r;) {
18+
if(s[l] === s[r]) {
19+
l++
20+
r--
21+
} else return false
22+
}
23+
return true
24+
}

0 commit comments

Comments
 (0)