Skip to content

Commit a7361d2

Browse files
authored
Merge pull request neetcode-gh#103 from ediazmen/Exercise-125
JS 125-Valid-Palindrome
2 parents 32ccc97 + 644487b commit a7361d2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

javascript/125-Valid-Palindrome.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ var isPalindrome = function(s) {
1616
j--
1717
}
1818
return true;
19-
};
19+
};

javascript/125-ValidPalindrome.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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--
20+
}
21+
return true
22+
}
23+
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))
28+
}
29+
30+
}

0 commit comments

Comments
 (0)