Skip to content

Commit ca075ef

Browse files
committed
valid palindrome solution
1 parent c620f71 commit ca075ef

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

valid-palindrome/JeonJe.java

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

0 commit comments

Comments
 (0)