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 027598f commit 806a21bCopy full SHA for 806a21b
valid-palindrome/njngwn.java
@@ -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