File tree Expand file tree Collapse file tree 1 file changed +15
-18
lines changed Expand file tree Collapse file tree 1 file changed +15
-18
lines changed Original file line number Diff line number Diff line change 3
3
* @return {boolean }
4
4
*/
5
5
const isPalindrome = function ( s ) {
6
- let start = 0
7
- let end = s . length - 1
6
+ let start = 0
7
+ let end = s . length - 1
8
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 --
9
+ while ( start < end ) {
10
+ while ( start < s . length && ! valid ( s [ start ] ) ) {
11
+ start ++
23
12
}
24
-
25
- return true
13
+ while ( end >= 0 && ! valid ( s [ end ] ) ) {
14
+ end --
15
+ }
16
+ if ( start < s . length && end >= 0 ) {
17
+ if ( s [ start ] . toLowerCase ( ) !== s [ end ] . toLowerCase ( ) ) return false
18
+ }
19
+ start ++
20
+ end --
21
+ }
22
+ return true
26
23
} ;
27
24
28
25
function valid ( c ) {
You can’t perform that action at this time.
0 commit comments