数组构成矩阵面积最大值 private static int maxArea(int[] height) { int maxArea = 0; int i = 0, j = height.length - 1; while (i j i = 0 j = height.length - 1) { maxArea = Math.max(maxArea, Math.min(height[i], height[j]) * (j - i));
private static int maxArea(int[] height) { int maxArea = 0; int i = 0, j = height.length - 1; while (i < j && i >= 0 && j <= height.length - 1) { maxArea = Math.max(maxArea, Math.min(height[i], height[j]) * (j - i)); if (height[i] > height[j]) j--; else i++; } return maxArea; }找到数组中三个数字之和为0的组
private static List> threeSum(int[] nums) { List
> ansList = new ArrayList<>(); if (nums.length < 3) return ansList; Arrays.sort(nums); for (int i = 0; i < nums.length - 2; i++) { if (i == 0 || nums[i - 1] < nums[i]) { int st = i + 1; int en = nums.length - 1; while (st < en) { int sum = nums[i] + nums[st] + nums[en]; if (sum == 0) { ansList.add(Arrays.asList(nums[i], nums[st], nums[en])); st++; en--; while (st < en && nums[st] == nums[st - 1]) st++; while (st < en && nums[en] == nums[en + 1]) en--; } else if (sum > 0) en--; else st++; } } } return ansList; }