Skip to content

Commit 2ea2642

Browse files
authored
Merge pull request #1863 from andynullwong/0680
Create 0680-valid-palindrome-ii.js
2 parents cf96600 + c81e260 commit 2ea2642

File tree

1 file changed

+34
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)