Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9027902

Browse files
refactor 125
1 parent498abd2 commit9027902

File tree

1 file changed

+24
-19
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+24
-19
lines changed
Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
packagecom.fishercoder.solutions;
22

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.
47
58
For example,
69
"A man, a plan, a canal: Panama" is a palindrome.
710
"race a car" is not a palindrome.
811
912
Note:
1013
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+
*/
1116

12-
For the purpose of this problem, we define empty string as valid palindrome.*/
1317
publicclass_125 {
1418

19+
publicstaticclassSolution1 {
1520
publicbooleanisPalindrome(Strings) {
16-
inti =0;
17-
intj =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-
returnfalse;
28-
}
29-
i++;
30-
j--;
21+
inti =0;
22+
intj =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--;
3130
}
32-
returntrue;
31+
if (Character.toLowerCase(chars[i]) !=Character.toLowerCase(chars[j])) {
32+
returnfalse;
33+
}
34+
i++;
35+
j--;
36+
}
37+
returntrue;
3338
}
34-
39+
}
3540
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp