LeetCode 11---Container With Most Water
2016-12-23 12:51
323 查看
题目链接:
LeetCode 11—Container With Most Water
本题是一个很容易想到的贪心思路,采用两个指针分别指向数组头、尾,每次移动短的那一边即可覆盖全部可能情况。
其实现代码如下:
LeetCode 11—Container With Most Water
本题是一个很容易想到的贪心思路,采用两个指针分别指向数组头、尾,每次移动短的那一边即可覆盖全部可能情况。
其实现代码如下:
public class Problem11 { public static void main(String[] args) { // TODO Auto-generated method stub } public static int maxArea(int[] height) { int i=0,j=height.length-1; int max=Math.min(height[i], height[j])*(height.length-1); while(i!=j){ if(height[i]<=height[j]){ i++; if(height[i]<=height[i-1]) continue; } else{ j--; if(height[j]<=height[j+1]) continue; } max=Math.max(max, (j-i)*Math.min(height[i], height[j])); } return max; } }
相关文章推荐
- leetcode[11]Container With Most Water
- leetcode-11 Container With Most Water
- leetcode_11题——Container With Most Water(两个指针)
- leetcode 11 -- Container With Most Water
- LeetCode 11 Container With Most Water
- [leetcode 11] Container With Most Water
- [Leetcode 11, Medium] Container With Most Water
- Container With Most Water - LeetCode 11
- LeetCode 11 - Container With Most Water
- Leetcode 11 Container With Most Water
- [LeetCode 11] Container With Most Water
- Java [leetcode 11] Container With Most Water
- Container With Most Water-Leetcode OJ Problem 11
- leetcode 11 -- Container With Most Water
- [leetcode 11] Container With Most Water
- LeetCode42/11 Trapping Rain Water/Container With Most Water/Hist area**
- LeetCode-11 Container With Most Water(容器装水最大量)
- LeetCode 11 Container With Most Water (C,C++,Java,Python)
- [Leetcode 43] 11 Container With Most Water
- [leetcode 11]Container With Most Water