We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dd0e8ec commit 9675dc5Copy full SHA for 9675dc5
1 file changed
valid-palindrome/hoonjichoi1.java
@@ -0,0 +1,23 @@
1
+class Solution {
2
+ public boolean isPalindrome(String s) {
3
+
4
+ // removing all non-alphanumeric characters and convert them to lower case
5
+ String conveted = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
6
7
+ // early return of the empty string case
8
+ if (conveted.length() == 0) {
9
+ return true;
10
+ }
11
12
+ // check the symmetry
13
+ int left = 0, right = conveted.length() - 1;
14
+ while (left <= right) {
15
+ if (conveted.charAt(left) != conveted.charAt(right)) {
16
+ return false;
17
18
+ left++;
19
+ right--;
20
21
22
23
+}
0 commit comments