Skip to content

Commit e8b4f8d

Browse files
committed
Exercise-125
1 parent d9d562f commit e8b4f8d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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)