File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ public boolean isPalindrome(String s){
2
+ if (s.length() >= 2){
3
+ int left = 0,right = s.length()-1;
4
+ char leftChar,rightChar;
5
+ while (left <= right){
6
+ leftChar = s.charAt(left);rightChar = s.charAt(right);
7
+ if (leftChar>='A'&&leftChar<='Z'){//转换大写字母为小写
8
+ leftChar+=32;
9
+ }else if (rightChar>='A'&&rightChar<='Z'){
10
+ rightChar+=32;
11
+ }
12
+ if (leftChar == rightChar){
13
+ left++;right--;
14
+ continue;
15
+ }
16
+ //跳过非字母非数字的字符
17
+ if (!((leftChar>='0'&& leftChar<='9') || (leftChar>='a'&&leftChar<='z') || (leftChar>='A'&&leftChar<='Z'))){
18
+ left++;
19
+ continue;
20
+ }else if (!((rightChar>='0'&& rightChar<='9') || (rightChar>='a'&&rightChar<='z') || (rightChar>='A'&&rightChar<='Z'))){
21
+ right--;
22
+ continue;
23
+ }
24
+ if (leftChar != rightChar)return false;
25
+ }
26
+ }
27
+ return true;
28
+ }
You can’t perform that action at this time.
0 commit comments