Re: [閒聊] LeetCode Blind Curated 75

看板 Marginalman
作者 yam276 (史萊哲林的優等生)
時間 2023-10-13 17:56:49
留言 0則留言 (0推 0噓 0→)

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 } } --
※ 批踢踢實業坊(ptt.cc), 來自: 60.248.143.163 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1697191011.A.229.html

您可能感興趣