File tree Expand file tree Collapse file tree 1 file changed +19
-18
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +19
-18
lines changed Original file line number Diff line number Diff line change 28
28
*/
29
29
public class _414 {
30
30
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 );
41
38
}
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 ) ;
47
44
}
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 );
49
52
}
50
- return (int ) (max3 == Long .MIN_VALUE ? max1 : max3 );
51
53
}
52
-
53
54
}
You can’t perform that action at this time.
0 commit comments