File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public boolean isPalindrome (String s ) {
3
+ s = s .toLowerCase ();
4
+
5
+ int left = 0 ;
6
+ int right = s .length () - 1 ;
7
+
8
+ while (left < right ) {
9
+
10
+ while (left < right && !Character .isLetterOrDigit (s .charAt (right ))) right --;
11
+ while (left < right && !Character .isLetterOrDigit (s .charAt (left ))) left ++;
12
+
13
+
14
+ if (s .charAt (left ++) != s .charAt (right --)) return false ;
15
+ }
16
+ return true ;
17
+ }
18
+
19
+ // public boolean isPalindrome(String s) {
20
+ // s = s.toLowerCase();
21
+
22
+ // int left = 0, right = s.length() - 1;
23
+ // while(left < right){
24
+
25
+ // while(left < right && !Character.isLetterOrDigit(s.charAt(right))) right--;
26
+ // while(left < right && !Character.isLetterOrDigit(s.charAt(left))) left++;
27
+
28
+ // if(s.charAt(left++) != s.charAt(right--)) return false;
29
+ // }
30
+ // return true;
31
+ // }
32
+ }
You can’t perform that action at this time.
0 commit comments