Skip to content

Commit cff44e3

Browse files
refactor 414
1 parent 63da990 commit cff44e3

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
public class _414 {
3030

31-
public int thirdMax(int[] nums) {
32-
long max1 = Long.MIN_VALUE;
33-
long max2 = Long.MIN_VALUE;
34-
long max3 = Long.MIN_VALUE;
35-
for (int i : nums) {
36-
max1 = Math.max(max1, i);
37-
}
38-
for (int i : nums) {
39-
if (i == max1) {
40-
continue;
31+
public static class Solution1 {
32+
public int thirdMax(int[] nums) {
33+
long max1 = Long.MIN_VALUE;
34+
long max2 = Long.MIN_VALUE;
35+
long max3 = Long.MIN_VALUE;
36+
for (int i : nums) {
37+
max1 = Math.max(max1, i);
4138
}
42-
max2 = Math.max(max2, i);
43-
}
44-
for (int i : nums) {
45-
if (i == max1 || i == max2) {
46-
continue;
39+
for (int i : nums) {
40+
if (i == max1) {
41+
continue;
42+
}
43+
max2 = Math.max(max2, i);
4744
}
48-
max3 = Math.max(max3, i);
45+
for (int i : 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy