Skip to content

Commit 42029fb

Browse files
authored
Create 680-valid-palindrome-ii.js
1 parent 2346a41 commit 42029fb

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

680-valid-palindrome-ii.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
6+
const validPalindrome = function(s) {
7+
let start = 0;
8+
let end = s.length - 1;
9+
10+
const isPalindrome = function(start, end, removed) {
11+
while (start <= end) {
12+
if (s[start] !== s[end]) {
13+
if (removed) {
14+
return false;
15+
}
16+
17+
return (
18+
isPalindrome(start + 1, end, true) ||
19+
isPalindrome(start, end - 1, true)
20+
);
21+
}
22+
start++;
23+
end--;
24+
}
25+
return true;
26+
};
27+
28+
return isPalindrome(start, end, false);
29+
};

0 commit comments

Comments
 (0)