File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -16,4 +16,4 @@ var isPalindrome = function(s) {
1616 j --
1717 }
1818 return true ;
19- } ;
19+ } ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments