package leetcode;

/**
 * https://leetcode.com/problems/maximum-product-of-three-numbers/
 */
public class Problem628 {
    public int maximumProduct(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem628 prob = new Problem628();
        System.out.println(prob.maximumProduct(new int[]{1, 2, 3})); // 6
        System.out.println(prob.maximumProduct(new int[]{1, 2, 3, 4})); // 24
        System.out.println(prob.maximumProduct(new int[]{-4, -3, -2, -1, 60})); // 720
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -195,368 +195,581 @@
     
-// TODO%0A        return 0
+Arrays.sort(nums);%0A        boolean positive = false
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem628 prob = new Problem628();%0A        System.out.println(prob.maximumProduct(new int%5B%5D%7B1, 2, 3%7D)); // 6%0A        System.out.println(prob.maximumProduct(new int%5B%5D%7B1, 2, 3, 4%7D)); // 24%0A        System.out.println(prob.maximumProduct(new int%5B%5D%7B-4, -3, -2, -1, 60%7D)); // 720
+boolean negative = false;%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            if (nums%5Bi%5D %3C 0) %7B%0A                negative = true;%0A            %7D else %7B%0A                positive = true;%0A            %7D%0A        %7D%0A        if (negative && positive) %7B%0A            int a = nums%5Bnums.length - 2%5D * nums%5Bnums.length - 3%5D;%0A            int b = nums%5B0%5D * nums%5B1%5D;%0A            return nums%5Bnums.length - 1%5D * Math.max(a, b);%0A        %7D%0A        return nums%5Bnums.length - 1%5D * nums%5Bnums.length - 2%5D * nums%5Bnums.length - 3%5D;
 %0A   

Solve problem 628