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

Commit7ae4ef0

Browse files
committed
Palindrome
1 parent1982bc2 commit7ae4ef0

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

‎dp/LongestPalindrome.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
publicclassLongestPalindrome {
44
publicstaticvoidmain(String[]args) {
5-
Strings ="cadfasdfsadfabaabaed";
5+
Strings ="9cadfasdfsadfabaabaed";
66
System.out.println(longestPalindrome(s));
7+
8+
System.out.println(Character.toLowerCase('9'));
9+
710
}
811

912
// Solution 1: Brute Force

‎string/IsPalindrome.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
packageAlgorithms.string;
2+
3+
publicclassIsPalindrome {
4+
publicbooleanisPalindrome(Strings) {
5+
// http://blog.csdn.net/fightforyourdream/article/details/12860445
6+
if (s ==null) {
7+
returnfalse;
8+
}
9+
10+
intlen =s.length();
11+
12+
s =s.toLowerCase();
13+
14+
intl =0;
15+
intr =len -1;
16+
while (l <r) {
17+
if (!isValid(s.charAt(l))) {
18+
l++;
19+
}elseif (!isValid(s.charAt(r))) {
20+
r--;
21+
}elseif (s.charAt(l) !=s.charAt(r)) {
22+
returnfalse;
23+
}else {
24+
l++;
25+
r--;
26+
}
27+
}
28+
29+
returntrue;
30+
}
31+
32+
publicbooleanisValid(charc) {
33+
returnCharacter.isLetterOrDigit(c);
34+
// if (c <= 'z' && c >= 'a' || c <= 'Z' && c >= 'A'
35+
// || c <= '9' && c >= '0') {
36+
// return true;
37+
// }
38+
39+
// return false;
40+
}
41+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp