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

Commit1982bc2

Browse files
committed
formate
1 parente9c90c8 commit1982bc2

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

‎dp/LongestPalindrome.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,42 @@ public static void main(String[] args) {
55
Strings ="cadfasdfsadfabaabaed";
66
System.out.println(longestPalindrome(s));
77
}
8-
8+
99
// Solution 1: Brute Force
1010
publicstaticStringlongestPalindrome(Strings) {
1111
if (s ==null) {
1212
returnnull;
1313
}
14-
14+
1515
intlen =s.length();
1616

1717
intmax =0;
1818
intbegin =0;
1919
intend =0;
2020
for (inti =0;i <len;i++) {
21-
for (intj =i;j <len;j++) {
22-
if (dfs(s,i,j)) {
23-
if (j -i +1 >max) {
24-
max =j -i +1;
25-
begin =i;
26-
end =j;
27-
}
28-
}
29-
}
21+
for (intj =i;j <len;j++) {
22+
if (dfs(s,i,j)) {
23+
if (j -i +1 >max) {
24+
max =j -i +1;
25+
begin =i;
26+
end =j;
27+
}
28+
}
29+
}
3030
}
31-
31+
3232
returns.substring(begin,end +1);
3333
}
3434

3535
publicstaticbooleandfs(Strings,inti,intj) {
3636
if (i >=j) {
3737
returntrue;
3838
}
39-
40-
if (s.charAt(i) ==s.charAt(j)) {
41-
returndfs(s,i +1,j -1);
42-
}
43-
44-
returnfalse;
39+
40+
if (s.charAt(i) ==s.charAt(j)) {
41+
returndfs(s,i +1,j -1);
42+
}
43+
44+
returnfalse;
4545
}
4646
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp