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 2828 */
2929public 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}
You can’t perform that action at this time.
0 commit comments