Skip to content

Commit 32d3f2e

Browse files
authored
Update 1147-longest-chunked-palindrome-decomposition.js
1 parent 0f7769b commit 32d3f2e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

1147-longest-chunked-palindrome-decomposition.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@ const longestDecomposition = function(text) {
1818
}
1919
return res
2020
}
21+
22+
// another
23+
24+
/**
25+
* @param {string} text
26+
* @return {number}
27+
*/
28+
const longestDecomposition = function(text) {
29+
let n = text.length
30+
for (let i = 0; i < Math.floor(n / 2); i++)
31+
if (text.slice(0, i + 1) === text.slice(n - 1 - i, n))
32+
return 2 + longestDecomposition(text.slice(i + 1, n - 1 - i))
33+
return n === 0 ? 0 : 1
34+
}

0 commit comments

Comments
 (0)