Leetcode 11. 盛最多水的容器

it2025-05-16  9

双指针思想

public class Solution { public int MaxArea(int[] height) { if (null == height || height.Length < 2) return 0; int left = 0; int right = height.Length - 1; int area = 0; while (left < right) { int nowarea = System.Math.Min(height[left], height[right]) * (right - left); area = System.Math.Max(area, nowarea); // 移动小值指针 if (height[left] < height[right]) { left++; } else { right--; } } return area; } }

 

最新回复(0)