11. Container With Most Water - Medium 前往題目 之前寫的文章 思路 2 pointers 只移動短的那邊,才有機會有更大的值 Codeclass Solution { public int maxArea(int[] height) { int l = 0, r = height.length - 1; int res = Integer.MIN_VALUE; while (l < r) { // Current square height int h = Math.min(height[l], height[r]); // Area int area = h * (r - l); // Store larger area if (area > res) { res = area; } // Move pointers if (height[l] > height[r]) { --r; } else { ++l; } } return res; } } Leetcode > Medium #Leetcode #心得 #Array #Greedy #Two Pointers 11. Container With Most Water - Medium https://f88083.github.io/2024/01/31/11-Container-With-Most-Water-Medium/ 作者 Simon Lai 發布於 2024年1月31日 許可協議 121. Best Time to Buy and Sell Stock - Easy 上一篇 125. Valid Palindrome - Easy 下一篇 Please enable JavaScript to view the comments