Skip to content

Commit 0f7769b

Browse files
authored
Create 1147-longest-chunked-palindrome-decomposition.js
1 parent d091018 commit 0f7769b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {string} text
3+
* @return {number}
4+
*/
5+
const longestDecomposition = function(text) {
6+
let res = 0,
7+
n = text.length
8+
let l = '',
9+
r = ''
10+
for (let i = 0; i < n; ++i) {
11+
l = l + text.charAt(i)
12+
r = text.charAt(n - i - 1) + r
13+
if (l === r) {
14+
++res
15+
l = ''
16+
r = ''
17+
}
18+
}
19+
return res
20+
}

0 commit comments

Comments
 (0)