-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# 11. 盛最多水的容器 | ||
|
||
> 难度:中等 | ||
给定一个长度为 n 的整数数组 height 。有 n 条垂线,第 i 条线的两个端点是 (i, 0) 和 (i, height[i]) 。 | ||
|
||
找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。 | ||
|
||
返回容器可以储存的最大水量。 | ||
|
||
说明:你不能倾斜容器。 | ||
|
||
```ts | ||
function maxArea(height: number[]): number { | ||
let left = 0; | ||
let right = height.length - 1; | ||
let res = 0; | ||
while(left < right) { | ||
if (height[left] < height[right]) { | ||
res = Math.max(res, height[left] * (right - left)); | ||
left++; | ||
} else { | ||
res = Math.max(res, height[right] * (right - left)); | ||
right--; | ||
} | ||
} | ||
|
||
return res; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
--- | ||
title: 面试经典150题 | ||
--- | ||
|
||
[12.整数转罗马数字](/leetcode/面试经典150题/12.整数转罗马数字) | ||
[121.买卖股票的最佳时机](/leetcode/面试经典150题/121.买卖股票的最佳时机) | ||
[122.买卖股票的最佳时机II](/leetcode/面试经典150题/122.买卖股票的最佳时机II) | ||
[122.买卖股票的最佳时机 II](/leetcode/面试经典150题/122.买卖股票的最佳时机II) | ||
[125.验证回文串](/leetcode/面试经典150题/125.验证回文串) | ||
[13.罗马数字转整数](/leetcode/面试经典150题/13.罗马数字转整数) | ||
[134.加油站](/leetcode/面试经典150题/134.加油站) | ||
[14.最长公共前缀](/leetcode/面试经典150题/14.最长公共前缀) | ||
[151.反转字符串中的单词](/leetcode/面试经典150题/151.反转字符串中的单词) | ||
[167.两数之和II-输入有序数组](/leetcode/面试经典150题/167.两数之和II-输入有序数组) | ||
[167.两数之和 II-输入有序数组](/leetcode/面试经典150题/167.两数之和II-输入有序数组) | ||
[169.多数元素](/leetcode/面试经典150题/169.多数元素) | ||
[189.轮转数组](/leetcode/面试经典150题/189.轮转数组) | ||
[26.删除有序数组中的重复项](/leetcode/面试经典150题/26.删除有序数组中的重复项) | ||
[27.移除元素](/leetcode/面试经典150题/27.移除元素) | ||
[380.O(1)时间插入、删除和获取随机元素](/leetcode/面试经典150题/380.O(1)时间插入、删除和获取随机元素) | ||
[380.O(1)时间插入、删除和获取随机元素](</leetcode/面试经典150题/380.O(1)时间插入、删除和获取随机元素>) | ||
[392.判断子序列](/leetcode/面试经典150题/392.判断子序列) | ||
[45.跳跃游戏II](/leetcode/面试经典150题/45.跳跃游戏II) | ||
[45.跳跃游戏 II](/leetcode/面试经典150题/45.跳跃游戏II) | ||
[55.跳跃游戏](/leetcode/面试经典150题/55.跳跃游戏) | ||
[58.最后一个单词的长度](/leetcode/面试经典150题/58.最后一个单词的长度) | ||
[6.N字形变换](/leetcode/面试经典150题/6.N字形变换) | ||
[80.删除有序数组中的重复项II](/leetcode/面试经典150题/80.删除有序数组中的重复项II) | ||
[6.N 字形变换](/leetcode/面试经典150题/6.N字形变换) | ||
[80.删除有序数组中的重复项 II](/leetcode/面试经典150题/80.删除有序数组中的重复项II) | ||
[88.合并两个有序数组](/leetcode/面试经典150题/88.合并两个有序数组) | ||
[11. 盛最多水的容器](/leetcode/面试经典150题/11.盛最多水的容器) |