给定一个整型数组,在数组中找出由三个数组成的最大乘积,并输出这个乘积。 示例 1: 输入: [1,2,3] 输出: 6 示例 2: 输入: [1,2,3,4] 输出: 24 public static int maximumProduct(int[] nums) { if (nums.length<3) return 0; int max1=-1000,max2=-1000,max3=-1000; int min1=1000,min2=1000; int i=0; while (i<nums.length) { if (nums[i]>=max1) { max3=max2; max2=max1; max1=nums[i]; }else if (nums[i]>=max2){ max3=max2; max2=nums[i]; }else if (nums[i]>=max3){ max3=nums[i]; } if (nums[i]<=min1) { min2=min1; min1=nums[i]; }else if (nums[i]<=min2){ min2=nums[i]; } i++; } System.out.println(max1); System.out.println(max2); System.out.println(max3); System.out.println(min1); System.out.println(min2); return Math.max(max1*max2*max3,max1*min1*min2); }