LeetCode Blind Curated 75:https://leetcode.com/list/xoqag3yj/
11. Container With Most Water
https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/17/question_11.jpg
找最高水面
由兩邊較高的高度決定
思路:
普通的雙指標題目
Code:
impl Solution {
pub fn max_area(height: Vec<i32>) -> i32 {
let mut left = 0;
let mut right = height.len() - 1;
let mut result = 0;
while left < right {
let water = (right - left) as i32 * height[left].min(height[right]
);
result = result.max(water);
if height[left] < height[right] {
left += 1;
} else {
right -= 1;
}
}
result
}
}