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 82f9399 commit 59a7607Copy full SHA for 59a7607
Java/Valid Palindrome.java
@@ -25,7 +25,28 @@ Hide Similar Problems (E) Palindrome Linked List
25
26
27
*/
28
-
+/*
29
+recap:
30
+Use regular expression [^a-zA-Z0-9] to replace all non-alphanumeric chars with ""
31
+*/
32
+public class Solution {
33
+ public boolean isPalindrome(String s) {
34
+ if (s == null || s.length() <= 1) {
35
+ return true;
36
+ }
37
+ final String str = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
38
+ int start = 0;
39
+ int end = str.length() - 1;
40
+ while (start < end) {
41
+ if (str.charAt(start) != str.charAt(end)) {
42
+ return false;
43
44
+ start++;
45
+ end--;
46
47
48
49
+}
50
51
/*
52
3.4.2016 recap
0 commit comments