LeetCode Note Java 00011:Container With Most Water
情境題:給定一系列長短不一的高,每個高坐落於間格為 1 的 x 軸上,求任意兩個高夾出的最大裝水容積。
題目
Container With Most Water Medium
You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return the maximum amount of water a container can store.
Notice that you may not slant the container.
我的解法
暴力解:
1 | class Solution { |
會超時。
Two Pointer:
1 | class Solution { |
參考資料
leetcode/java/0011-container-with-most-water.java