File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -18,22 +18,22 @@ public class ValidPalindrome {
18
18
public boolean isPalindrome (String s ) {
19
19
s = s .toUpperCase ();
20
20
int i = 0 , j = s .length () - 1 ;
21
- while (true ) {
22
- while (i < s .length ()
23
- && !(s .charAt (i ) >= 'A' && s .charAt (i ) <= 'Z' )
24
- && !(s .charAt (i ) >= '0' && s .charAt (i ) <= '9' ))
21
+ while (i < j ) {
22
+ if (!isAlphabet (s .charAt (i ))) {
25
23
i ++;
26
- while (j >= 0 && !(s .charAt (j ) >= 'A' && s .charAt (j ) <= 'Z' )
27
- && !(s .charAt (j ) >= '0' && s .charAt (j ) <= '9' ))
24
+ } else if (!isAlphabet (s .charAt (j ))) {
28
25
j --;
29
- if (i >= j ) {
30
- return true ;
31
26
} else if (s .charAt (i ) != s .charAt (j )) {
32
27
return false ;
33
28
} else {
34
29
i ++;
35
30
j --;
36
31
}
37
32
}
33
+ return true ;
34
+ }
35
+
36
+ private boolean isAlphabet (char c ) {
37
+ return (c >= 'A' && c <= 'Z' ) || (c >= '0' && c <= '9' );
38
38
}
39
39
}
You can’t perform that action at this time.
0 commit comments