File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public boolean isPalindrome (String s ) {
3
+ // Base case
4
+ if (s .isEmpty ())
5
+ return true ;
6
+
7
+ // Two pointer method
8
+ int l = 0 ;
9
+ int r = s .length () - 1 ;
10
+
11
+ while (l < r ) {
12
+ // Move l untill find a letter or number
13
+ while (l < r && !Character .isLetterOrDigit (s .charAt (l )))
14
+ l ++;
15
+
16
+ // Move r untill find a letter or number
17
+ while (l < r && !Character .isLetterOrDigit (s .charAt (r )))
18
+ r --;
19
+
20
+ char l_ch = s .charAt (l );
21
+ char r_ch = s .charAt (r );
22
+
23
+ if (l_ch >= 'A' && l_ch <= 'Z' )
24
+ l_ch = (char )(l_ch + 32 );
25
+
26
+ if (r_ch >= 'A' && r_ch <= 'Z' )
27
+ r_ch = (char )(r_ch + 32 );
28
+
29
+ // Check if letter in l and r are matches
30
+ if (l_ch != r_ch )
31
+ return false ;
32
+
33
+ l ++;
34
+ r --;
35
+ }
36
+
37
+ return true ;
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments