int maxArea(vector<int>& height) {
int best = 0;
int n = height.size();
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int area = min(height[i], height[j]) * (j - i);
best = max(best, area);
}
}
return best;
}
public int maxArea(int[] height) {
int best = 0;
int n = height.length;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int area = Math.min(height[i], height[j]) * (j - i);
best = Math.max(best, area);
}
}
return best;
}
def max_area(height: list[int]) -> int:
best = 0
n = len(height)
for i in range(n):
for j in range(i + 1, n):
area = min(height[i], height[j]) * (j - i)
best = max(best, area)
return best
function maxArea(height: number[]): number {
let best = 0;
for (let i = 0; i < height.length; i++) {
for (let j = i + 1; j < height.length; j++) {
const area = Math.min(height[i], height[j]) * (j - i);
best = Math.max(best, area);
}
}
return best;
}
int maxArea(vector<int>& height) {
int best = 0;
int n = height.size();
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
if (height[i] * (j - i) <= best) break;
best = max(best, min(height[i], height[j]) * (j - i));
}
}
return best;
}
public int maxArea(int[] height) {
int best = 0;
int n = height.length;
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
if (height[i] * (j - i) <= best) break;
best = Math.max(best, Math.min(height[i], height[j]) * (j - i));
}
}
return best;
}
def max_area(height: list[int]) -> int:
best = 0
n = len(height)
for i in range(n):
for j in range(n - 1, i, -1):
if height[i] * (j - i) <= best: break
best = max(best, min(height[i], height[j]) * (j - i))
return best
function maxArea(height: number[]): number {
let best = 0;
for (let i = 0; i < height.length; i++) {
for (let j = height.length - 1; j > i; j--) {
if (height[i] * (j - i) <= best) break;
best = Math.max(best, Math.min(height[i], height[j]) * (j - i));
}
}
return best;
}
int maxArea(vector<int>& height) {
int left = 0;
int right = (int)height.size() - 1;
int best = 0;
while (left < right) {
int area = min(height[left], height[right]) * (right - left);
best = max(best, area);
if (height[left] < height[right]) left++;
else right--;
}
return best;
}
public int maxArea(int[] height) {
int left = 0;
int right = height.length - 1;
int best = 0;
while (left < right) {
int area = Math.min(height[left], height[right]) * (right - left);
best = Math.max(best, area);
if (height[left] < height[right]) left++;
else right--;
}
return best;
}
def max_area(height: list[int]) -> int:
left = 0
right = len(height) - 1
best = 0
while left < right:
area = min(height[left], height[right]) * (right - left)
best = max(best, area)
if height[left] < height[right]: left += 1
else: right -= 1
return best
function maxArea(height: number[]): number {
let left = 0;
let right = height.length - 1;
let best = 0;
while (left < right) {
const area = Math.min(height[left], height[right]) * (right - left);
best = Math.max(best, area);
if (height[left] < height[right]) left++;
else right--;
}
return best;
}
long long maxArea(const vector<int>& height) {
int left = 0;
int right = (int)height.size() - 1;
long long best = 0;
while (left < right) {
int hl = height[left];
int hr = height[right];
int h = hl < hr ? hl : hr;
long long area = (long long)h * (right - left);
if (area > best) best = area;
if (hl < hr) {
while (left < right && height[left] <= h) left++;
} else {
while (left < right && height[right] <= h) right--;
}
}
return best;
}
public long maxArea(int[] height) {
int left = 0;
int right = height.length - 1;
long best = 0;
while (left < right) {
int hl = height[left];
int hr = height[right];
int h = hl < hr ? hl : hr;
long area = (long) h * (right - left);
if (area > best) best = area;
if (hl < hr) {
while (left < right && height[left] <= h) left++;
} else {
while (left < right && height[right] <= h) right--;
}
}
return best;
}
def max_area(height: Sequence[int]) -> int:
left = 0
right = len(height) - 1
best = 0
while left < right:
hl = height[left]
hr = height[right]
h = hl if hl < hr else hr
area = h * (right - left)
if area > best: best = area
if hl < hr:
while left < right and height[left] <= h: left += 1
else:
while left < right and height[right] <= h: right -= 1
return best
function maxArea(height: ArrayLike<number>): number {
let left = 0;
let right = height.length - 1;
let best = 0;
while (left < right) {
const hl = height[left];
const hr = height[right];
const h = hl < hr ? hl : hr;
const area = h * (right - left);
if (area > best) best = area;
if (hl < hr) {
while (left < right && height[left] <= h) left++;
} else {
while (left < right && height[right] <= h) right--;
}
}
return best;
}