File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ function isPalindrome ( s : string ) : boolean {
2+ let start = 0 ;
3+ let last = s . length - 1 ;
4+ while ( start < last ) {
5+ while ( start < last && ! isAlphanumeric ( s . charAt ( start ) ) ) {
6+ start += 1 ;
7+ }
8+ while ( start < last && ! isAlphanumeric ( s . charAt ( last ) ) ) {
9+ last -= 1 ;
10+ }
11+ if ( s . charAt ( start ) . toLowerCase ( ) !== s . charAt ( last ) . toLowerCase ( ) ) {
12+ return false ;
13+ }
14+ start += 1 ;
15+ last -= 1 ;
16+ }
17+ return true ;
18+ }
19+
20+ function isAlphanumeric ( character : string ) {
21+ const characterCode = character . charCodeAt ( 0 ) ;
22+ const lowerStart = "a" . charCodeAt ( 0 ) ;
23+ const lowerEnd = "z" . charCodeAt ( 0 ) ;
24+ const upperStart = "A" . charCodeAt ( 0 ) ;
25+ const upperEnd = "Z" . charCodeAt ( 0 ) ;
26+ const numericStart = "0" . charCodeAt ( 0 ) ;
27+ const numericEnd = "9" . charCodeAt ( 0 ) ;
28+ if ( upperStart <= characterCode && upperEnd >= characterCode ) {
29+ return true ;
30+ }
31+ if ( lowerStart <= characterCode && lowerEnd >= characterCode ) {
32+ return true ;
33+ }
34+ if ( numericStart <= characterCode && numericEnd >= characterCode ) {
35+ return true ;
36+ }
37+ return false ;
38+ }
You can’t perform that action at this time.
0 commit comments