LeetCode之双指针(3)
来源:互联网 发布:淘宝2017年双十一 编辑:程序博客网 时间:2024/05/23 15:07
11. Container With Most Water
题目链接:
https://leetcode.com/problems/container-with-most-water/
题目描述:
给一个高度数组,代表x轴上有一些给定高度的竖线,求两条竖线与x轴构成的容器能容纳最大多少的水面积。
题目分析:
curCapacity=min(height[low],height[high])*(high-low)
感谢
http://www.th7.cn/Program/c/201505/447082.shtml
一开始没懂题几个意思啊,求能装多少水,这咋算底面积啊。
双指针,一个从头开始走,一个从尾开始走,高度小的前进,为看之后有没有高度大的来更新curCapacity。
代码:
class Solution {public: int maxArea(vector<int>& height) { int low=0; int high=height.size()-1; int capacity=0; int cur=0; while(low<high){ cur=min(height[low],height[high])*(high-low); if(capacity<cur){ capacity=cur; } if(height[low]>height[high]){ high--; } else{ low++; } } return capacity; }};
0 0
- LeetCode之双指针(3)
- LeetCode之双指针(1)
- LeetCode之双指针(2)
- LeetCode 之双指针 two pointers
- LeetCode|【双指针】
- 双指针-Leetcode
- Leetcode双指针16
- leetcode链表拷贝之随机指针
- leetcode ---双指针+滑动窗口
- 【Leetcode】3Sum - 【两个指针】
- leetcode 3---Longest Substring Without Repeating Characters 双指针 String
- LeetCode 之K-Sum 问题(个人理解) 双指针大法(总结)
- leetcode之双指针类-----OJ 228/15/16/18/26/80/121/75
- 双指针,前后指针法, 快排思路, leetcode
- leetcode 287. Find the Duplicate Number 双指针 + 快慢指针
- [Leetcode][双指针/多指针]相关题目汇总/分析/总结
- leetcode之有随机指针的链表深拷贝
- LeetCode:Valid Palindrome双指针 java版
- Apache+tomcat集群(负载均衡)
- Android Handler 四个使用实例 及HandlerThread的使用,androidhandler实例,HandlerThread 源码分析
- appium安装
- 选择之后,再返回来还是之前选择的
- Android 的Otto插件的使用
- LeetCode之双指针(3)
- java开发记录
- 印刷行业合版BOM全阶维护示例
- listView单选实现的两种方式
- 4029: [HEOI2015]定价 贪心
- Android的UI底层是用CPU绘图的还是GPU绘图的呢?以及surfaceview,window,普通view是如何实现的?
- 5-19 支票面额
- Smart210一键部署运行qt程序
- 好用的jquery分页插件 kkpager