leetcode 11.盛最多水的容器
2018-03-25 18:31
405 查看
11. 盛最多水的容器
双指针法,挺常用的,学习一下。class MaxArea { public: int maxArea(vector<int>& height) { if (height.size() < 2) { return 0; } int nLeft = 0; int nRight = height.size() - 1; int nMaxArea = 0; while (nLeft < nRight) { int nLeftVal = height[nLeft]; int nRightVal = height[nRight]; int nVal = nLeftVal < nRightVal ? nLeftVal:nRightVal; if (nMaxArea < nVal * (nRight - nLeft)) { nMaxArea = nVal * (nRight - nLeft); } if (nLeftVal < nRightVal) { nLeft++; } else { nRight--; } } return nMaxArea; } };
相关文章推荐
- Leetcode 11. 盛最多水的容器
- LeetCode 11. Container With Most Water (装最多水的容器)
- leetcode 11 Container With Most Water(最大水容器)
- LeetCode-11 Container With Most Water(容器装水最大量)
- leetcode笔记—容纳最多水的容器
- 11. 盛最多水的容器 Container With Most Water
- 11.盛最多水的容器(Container With Most Water)
- LeetCode 11 Container With Most Water(最大水容器)
- [LeetCode] Container With Most Water 装最多水的容器
- Container With Most Water 求容器里能放最多的水 @LeetCode
- Leetcode刷题记——11. Container With Most Water(装最多水的容器)
- leetcode-java.T011_ContainerWithMostWater 找两条竖线然后这两条线以及X轴构成的容器能容纳最多的水
- [LeetCode] 11. Container With Most Water 装最多水的容器
- leetcode-11-dfs
- leetCode 11
- leetcode Majority Element 寻找出现次数最多元素
- Container with most water_Leetcode_#11
- LeetCode 11: Container With Most Water
- leetcode(11),Power of Three(python)
- 11_容器窗口