Skip to content

Commit 60c6a15

Browse files
committed
Merge pull request neetcode-gh#194 from thisiswhale/patch-1
Fixed 125-Valid-Palindrome.js
2 parents 681f97a + 1adba3f commit 60c6a15

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

javascript/125-ValidPalindrome.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
class isValidPalindrome {
2-
constructor(string){
3-
this.string=string;
4-
}
5-
isPalindrome(string){
6-
let left =0;
7-
let right=string.length-1;
8-
while(left<right){
9-
while(left<right && this.isAlphaNumeric(string[left])){
10-
left++
11-
}
12-
while(right>left && this.isAlphaNumeric(string[right])){
13-
right--
14-
}
15-
if(string[left].toLowerCase()!=string[right].toLowerCase()) {
16-
return false;
17-
}
18-
left++
19-
right--
1+
var isPalindrome = function(s) {
2+
let l = 0, r = s.length-1;
3+
while(l<r){
4+
while(l < r && !isAlphaNumeric(s[l])){
5+
l++;
6+
}
7+
while(r > l && !isAlphaNumeric(s[r])){
8+
r--;
209
}
21-
return true
10+
if(s[l].toLowerCase() !== s[r].toLowerCase()) return false;
11+
l++;
12+
r--;
2213
}
14+
return true;
2315

24-
isAlphaNumeric(c){
25-
return ('A'.charCodeAt(0) <= c.charCodeAt(0) <='Z'.charCodeAt(0) ||
26-
'a'.charCodeAt(0) <= c.charCodeAt(0) <='z'.charCodeAt(0) ||
27-
'0'.charCodeAt(0) <= c.charCodeAt(0) <='9'.charCodeAt(0))
16+
function isAlphaNumeric(c){
17+
return (
18+
('A'.charCodeAt(0) <= c.charCodeAt(0) && c.charCodeAt(0) <= 'Z'.charCodeAt(0)) ||
19+
('a'.charCodeAt(0) <= c.charCodeAt(0) && c.charCodeAt(0) <= 'z'.charCodeAt(0)) ||
20+
('0'.charCodeAt(0) <= c.charCodeAt(0) && c.charCodeAt(0) <= '9'.charCodeAt(0))
21+
)
2822
}
29-
30-
}
23+
};

0 commit comments

Comments
 (0)