File tree 1 file changed +6
-5
lines changed
scripts/algorithms/M/Maximum Product of Three Numbers
1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 2 ms (Top 99.90%) | Memory: 54.7 MB (Top 23.03%)
1
2
class Solution {
2
3
public int maximumProduct (int [] nums ) {
3
4
int min1 = Integer .MAX_VALUE , min2 = Integer .MAX_VALUE ;
@@ -6,20 +7,20 @@ public int maximumProduct(int[] nums) {
6
7
if (n <= min1 ) {
7
8
min2 = min1 ;
8
9
min1 = n ;
9
- } else if (n <= min2 ) { // n lies between min1 and min2
10
+ } else if (n <= min2 ) { // n lies between min1 and min2
10
11
min2 = n ;
11
12
}
12
- if (n >= max1 ) { // n is greater than max1, max2 and max3
13
+ if (n >= max1 ) { // n is greater than max1, max2 and max3
13
14
max3 = max2 ;
14
15
max2 = max1 ;
15
16
max1 = n ;
16
- } else if (n >= max2 ) { // n lies betweeen max1 and max2
17
+ } else if (n >= max2 ) { // n lies betweeen max1 and max2
17
18
max3 = max2 ;
18
19
max2 = n ;
19
- } else if (n >= max3 ) { // n lies betwen max2 and max3
20
+ } else if (n >= max3 ) { // n lies betwen max2 and max3
20
21
max3 = n ;
21
22
}
22
23
}
23
24
return Math .max (min1 * min2 * max1 , max1 * max2 * max3 );
24
25
}
25
- }
26
+ }
You can’t perform that action at this time.
0 commit comments