Skip to content

Commit 7edcc4b

Browse files
authored
Create 1616-split-two-strings-to-make-palindrome.js
1 parent 88a3042 commit 7edcc4b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @param {string} a
3+
* @param {string} b
4+
* @return {boolean}
5+
*/
6+
const checkPalindromeFormation = function(a, b) {
7+
return helper(a, b) || helper(b, a)
8+
};
9+
10+
function helper(A, B) {
11+
const str_len = A.length
12+
let idx = 0
13+
while(A[idx] === B[str_len - idx - 1]) {
14+
idx += 1
15+
}
16+
console.log(idx)
17+
if (idx > Math.floor(str_len / 2) ) return true
18+
else if (chk(A.slice(idx + 1, str_len - idx - 2 + 1))) return true
19+
else if (chk(B.slice(idx + 1, str_len - idx - 2 + 1))) return true
20+
else return false
21+
}
22+
23+
function chk(s) {
24+
let l = 0, r = s.length - 1
25+
while(l < r) {
26+
if(s[l] !== s[r]) return false
27+
l++
28+
r--
29+
}
30+
return true
31+
}

0 commit comments

Comments
 (0)