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.
2 parents 62a1e92 + 9d04ca6 commit 76e450bCopy full SHA for 76e450b
2018.11.27-leetcode125/ChenforCode.md
@@ -0,0 +1,30 @@
1
+/**
2
+ * @author: ChenforCode
3
+ * @date: 2018/11/26 14:29
4
+ * @description: 验证回文串,只验证数字和字符
5
+ */
6
+public class Solution {
7
+ public static void main(String[] args){
8
+ System.out.println(isPalindrome("A man, a plan, a canal: Panama"));
9
+ }
10
+
11
+ public static boolean isPalindrome(String s) {
12
+ char[] chars = s.toCharArray();
13
+ int i = 0, j = chars.length - 1;
14
+ while (i < j){
15
+ if (!Character.isLetterOrDigit(chars[i])){
16
+ i++;
17
+ } else if (!Character.isLetterOrDigit(chars[j])){
18
+ j--;
19
+ } else {
20
+ if (Character.toLowerCase(chars[i]) == Character.toLowerCase(chars[j])){
21
22
23
24
+ return false;
25
26
27
28
+ return true;
29
30
+}
0 commit comments