Skip to content

Commit 806a21b

Browse files
author
Jeongwon Na
committed
valid palindrome solution
1 parent 027598f commit 806a21b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

valid-palindrome/njngwn.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public boolean isPalindrome(String s) {
3+
s = s.toLowerCase(); // convert into lowercase letters
4+
s = s.replaceAll("[^a-zA-Z0-9]", ""); // remove non-alphanumeric characters
5+
int start = 0;
6+
int end = s.length()-1;
7+
8+
while (start < end) {
9+
char startChar = s.charAt(start);
10+
char endChar = s.charAt(end);
11+
12+
if (startChar != endChar) {
13+
return false;
14+
}
15+
16+
++start;
17+
--end;
18+
}
19+
20+
return true;
21+
}
22+
}

0 commit comments

Comments
 (0)