Skip to content

Commit 41c2228

Browse files
committed
2 pointers
1 parent d1177fc commit 41c2228

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

‎125.Valid Palindrome/medium.java

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
public class medium {
2+
3+
public boolean isPalindrome(String s) {
4+
int left=0;
5+
int right=s.length()-1;
6+
7+
while(left<right){
8+
//check if left is not alpha num
9+
while(left<right && !Character.isLetterOrDigit(s.charAt(left))){
10+
left++;
11+
}
12+
while(left<right && !Character.isLetterOrDigit(s.charAt(right))){
13+
right--;
14+
}
15+
if(Character.toLowerCase(s.charAt(left)) !=Character.toLowerCase(s.charAt(right))){
16+
return false;
17+
18+
}
19+
20+
left++;
21+
right--;
22+
23+
24+
25+
26+
27+
28+
29+
}
30+
31+
return true;
32+
33+
34+
35+
}
36+
37+
}

0 commit comments

Comments
 (0)