Skip to content

Commit 9aaaf5f

Browse files
committed
valid palindrome solved
1 parent 56f2013 commit 9aaaf5f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

valid-palindrome/sora0319.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public boolean isPalindrome(String s) {
3+
int start = 0;
4+
int end = s.length()-1;
5+
6+
boolean isPalindrome = true;
7+
s = s.toLowerCase();
8+
9+
while(start <= end){
10+
if((s.charAt(start) < 'a' || s.charAt(start) > 'z') && (s.charAt(start) < '0' || s.charAt(start) > '9')){
11+
start++;
12+
continue;
13+
}
14+
if((s.charAt(end) < 'a' || s.charAt(end) > 'z') && (s.charAt(end) < '0' || s.charAt(end) > '9')){
15+
end--;
16+
continue;
17+
}
18+
if(s.charAt(start) != s.charAt(end)) return false;
19+
start++;
20+
end--;
21+
22+
}
23+
24+
return isPalindrome;
25+
}
26+
}
27+

0 commit comments

Comments
 (0)