File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
Leetcode/Leetcode_August_Challenge Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change 33public class Valid_Palindrome {
44
55 public boolean isPalindrome (String s ) {
6-
6+ // check string if it's null no need to go further direct return false
7+
78 if (s ==null ){
89 return false ;
910 }
10-
11+
12+ // if string contain some char as uppercase or lowercase
13+ // this will convert whole string to lowercase
1114 s = s .toLowerCase ();
1215
16+ // pointed i to intially at 0
17+ // and j to end of the string (last character)
1318 int i =0 ;
1419 int j =s .length ()-1 ;
1520
21+
1622 while (i <j ){
23+ //if i<j and string char contain a-z and 0-9 loop -> true
24+
1725 while (i <j && !((s .charAt (i )>='a' && s .charAt (i )<='z' )
1826 || (s .charAt (i )>='0' &&s .charAt (i )<='9' ))){
1927 i ++;
@@ -23,15 +31,16 @@ public boolean isPalindrome(String s) {
2331 || (s .charAt (j )>='0' &&s .charAt (j )<='9' ))){
2432 j --;
2533 }
26-
34+ // if one of string char not match i to j
35+ // it will return false
2736 if (s .charAt (i ) != s .charAt (j )){
2837 return false ;
2938 }
30-
39+
3140 i ++;
3241 j --;
3342 }
34-
43+ // else return true
3544 return true ;
3645
3746 }
You can’t perform that action at this time.
0 commit comments