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

Commitcff44e3

Browse files
refactor 414
1 parent63da990 commitcff44e3

File tree

1 file changed

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

1 file changed

+19
-18
lines changed

‎src/main/java/com/fishercoder/solutions/_414.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,27 @@
2828
*/
2929
publicclass_414 {
3030

31-
publicintthirdMax(int[]nums) {
32-
longmax1 =Long.MIN_VALUE;
33-
longmax2 =Long.MIN_VALUE;
34-
longmax3 =Long.MIN_VALUE;
35-
for (inti :nums) {
36-
max1 =Math.max(max1,i);
37-
}
38-
for (inti :nums) {
39-
if (i ==max1) {
40-
continue;
31+
publicstaticclassSolution1 {
32+
publicintthirdMax(int[]nums) {
33+
longmax1 =Long.MIN_VALUE;
34+
longmax2 =Long.MIN_VALUE;
35+
longmax3 =Long.MIN_VALUE;
36+
for (inti :nums) {
37+
max1 =Math.max(max1,i);
4138
}
42-
max2 =Math.max(max2,i);
43-
}
44-
for (inti :nums) {
45-
if (i ==max1 ||i ==max2) {
46-
continue;
39+
for (inti :nums) {
40+
if (i ==max1) {
41+
continue;
42+
}
43+
max2 =Math.max(max2,i);
4744
}
48-
max3 =Math.max(max3,i);
45+
for (inti :nums) {
46+
if (i ==max1 ||i ==max2) {
47+
continue;
48+
}
49+
max3 =Math.max(max3,i);
50+
}
51+
return (int) (max3 ==Long.MIN_VALUE ?max1 :max3);
4952
}
50-
return (int) (max3 ==Long.MIN_VALUE ?max1 :max3);
5153
}
52-
5354
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp