2、 public int minimumDeviation(int[] nums) { Arrays.sort(nums); int len = nums.length; int min = nums[0]; int max = nums[len - 1]; boolean left = (min &; 1) == 0; boolean right = (max &; 1) == 1; while (!left || !right){ if (left &;&; !right){ nums[len - 1] /=2; }else if (!left &;&; right){ nums[0] *= 2; }else{ nums[0] *= 2; nums[len - 1] /=2; } Arrays.sort(nums); min = nums[0]; max = nums[len - 1]; left = (min &; 1) == 0; right = (max &; 1) == 1; } return max - min; }
1 1
牛客网
牛客企业服务