File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } s
3
+ * @return {boolean }
4
+ */
5
+ const isPalindrome = function ( s ) {
6
+ let start = 0
7
+ let end = s . length - 1
8
+
9
+ let char = ''
10
+ while ( start < end ) {
11
+ while ( start < s . length && ! valid ( s [ start ] ) ) {
12
+ start ++
13
+ }
14
+ while ( end >= 0 && ! valid ( s [ end ] ) ) {
15
+ end --
16
+ }
17
+ if ( start < s . length && end >= 0 ) {
18
+ if ( s [ start ] . toLowerCase ( ) !== s [ end ] . toLowerCase ( ) ) return false
19
+ }
20
+
21
+ start ++
22
+ end --
23
+ }
24
+
25
+ return true
26
+ } ;
27
+
28
+ function valid ( c ) {
29
+ const code = c . toLowerCase ( ) . charCodeAt ( 0 )
30
+ const zeroCode = ( '0' ) . charCodeAt ( 0 )
31
+ const nineCode = ( '9' ) . charCodeAt ( 0 )
32
+ const aCode = ( 'a' ) . charCodeAt ( 0 )
33
+ const zCode = ( 'z' ) . charCodeAt ( 0 )
34
+ if ( ( code >= zeroCode && code <= nineCode ) || ( code >= aCode && code <= zCode ) ) return true
35
+
36
+ return false
37
+ }
You can’t perform that action at this time.
0 commit comments