Skip to content

Commit ff39fde

Browse files
committed
valid palindrome solution
1 parent 39be389 commit ff39fde

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

valid-palindrome/eunhwa99.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public boolean isPalindrome(String s) {
3+
StringBuilder str = new StringBuilder();
4+
5+
for (int i = 0; i < s.length(); i++) {
6+
char c = s.charAt(i);
7+
if (Character.isLetterOrDigit(c)) {
8+
str.append(Character.toLowerCase(c));
9+
}
10+
}
11+
12+
int left = 0, right = str.length() - 1;
13+
while (left < right) {
14+
if (str.charAt(left) != str.charAt(right)) {
15+
return false;
16+
}
17+
left++;
18+
right--;
19+
}
20+
21+
return true;
22+
}
23+
}

0 commit comments

Comments
 (0)