Skip to content

Commit bcb9ff5

Browse files
authored
Create 湛江甲鸟.md
1 parent f39f142 commit bcb9ff5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

2018.11.26/湛江甲鸟.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
```
2+
public boolean isPalindrome(String s) {
3+
char[] chars = s.toLowerCase().toCharArray();
4+
int start = 0;
5+
int end = chars.length - 1;
6+
while (start < end) {
7+
char ch1 = chars[start];
8+
char ch2 = chars[end];
9+
if (!isLetterOrNum(ch1)) {
10+
start++;
11+
} else if (!isLetterOrNum(ch2)){
12+
end--;
13+
} else {
14+
if (ch1 == ch2) {
15+
start++;
16+
end--;
17+
18+
} else {
19+
return false;
20+
}
21+
}
22+
23+
}
24+
25+
return true;
26+
}
27+
28+
public static boolean isLetterOrNum(char ch) {
29+
String pattern = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
30+
if (pattern.contains(String.valueOf(ch))) {
31+
return true;
32+
}
33+
34+
return false;
35+
}

0 commit comments

Comments
 (0)