Skip to content

Commit a925b55

Browse files
authored
Update Maximum Product of three numbers.java
1 parent 89bf396 commit a925b55

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Easy/Maximum Product of three numbers.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ class Solution {
22
public int maximumProduct(int[] nums) {
33
Arrays.sort(nums);
44
int n = nums.length;
5-
int rightSideProd = nums[n - 1] * nums[n - 2] * nums[n - 3];
6-
int leftSideProd = nums[0] * nums[1] * nums[2];
7-
int mixedSideProd = nums[0] * nums[1] * nums[n - 1];
8-
return Math.max(rightSideProd, Math.max(leftSideProd, mixedSideProd));
5+
int lastThree = nums[n - 1] * nums[n - 2] * nums[n - 3];
6+
int firstTwoAndLast = nums[0] * nums[1] * nums[n - 1];
7+
return Math.max(lastThree, firstTwoAndLast);
98
}
109
}

0 commit comments

Comments
 (0)