628. Maximum Product of Three Numbers

1
2
3
4
5
6
7
8
9
10
class Solution {
public int maximumProduct(int[] nums) {
Arrays.sort(nums);

int maxProduct = Integer.MIN_VALUE;
maxProduct = Math.max(maxProduct, nums[nums.length - 3] * nums[nums.length - 2] * nums[nums.length - 1]);
maxProduct = Math.max(maxProduct, nums[0] * nums[1] * nums[nums.length - 1]);
return maxProduct;
}
}

References

628. Maximum Product of Three Numbers