File tree 1 file changed +24
-19
lines changed
src/main/java/com/fishercoder/solutions 1 file changed +24
-19
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
- /**Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
3
+ /**
4
+ * 125. Valid Palindrome
5
+
6
+ Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
4
7
5
8
For example,
6
9
"A man, a plan, a canal: Panama" is a palindrome.
7
10
"race a car" is not a palindrome.
8
11
9
12
Note:
10
13
Have you consider that the string might be empty? This is a good question to ask during an interview.
14
+ For the purpose of this problem, we define empty string as valid palindrome.
15
+ */
11
16
12
- For the purpose of this problem, we define empty string as valid palindrome.*/
13
17
public class _125 {
14
18
19
+ public static class Solution1 {
15
20
public boolean isPalindrome (String s ) {
16
- int i = 0 ;
17
- int j = s .length () - 1 ;
18
- char [] chars = s .toCharArray ();
19
- while (i < j ) {
20
- while (i < j && !Character .isLetterOrDigit (chars [i ])) {
21
- i ++;
22
- }
23
- while (i < j && !Character .isLetterOrDigit (chars [j ])) {
24
- j --;
25
- }
26
- if (Character .toLowerCase (chars [i ]) != Character .toLowerCase (chars [j ])) {
27
- return false ;
28
- }
29
- i ++;
30
- j --;
21
+ int i = 0 ;
22
+ int j = s .length () - 1 ;
23
+ char [] chars = s .toCharArray ();
24
+ while (i < j ) {
25
+ while (i < j && !Character .isLetterOrDigit (chars [i ])) {
26
+ i ++;
27
+ }
28
+ while (i < j && !Character .isLetterOrDigit (chars [j ])) {
29
+ j --;
31
30
}
32
- return true ;
31
+ if (Character .toLowerCase (chars [i ]) != Character .toLowerCase (chars [j ])) {
32
+ return false ;
33
+ }
34
+ i ++;
35
+ j --;
36
+ }
37
+ return true ;
33
38
}
34
-
39
+ }
35
40
}
You can’t perform that action at this time.
0 commit comments