leetcode -- Trapping Rain Water -- 重点
来源:互联网 发布:搜狗输入法 编程皮肤 编辑:程序博客网 时间:2024/05/29 06:58
https://leetcode.com/problems/trapping-rain-water/
思路很简单,但是不容易想到。求每一个i的储水量
参考http://www.cnblogs.com/zuoyuan/p/3781453.html
还有很多其他解法:
http://www.cnblogs.com/tenosdoit/p/3812880.html
class Solution(object): def trap(self, height): """ :type height: List[int] :rtype: int """ leftmosthigh = [] leftmax = 0 for x in height: #i左边的最大值,不包括i。所以leftmosthigh【0】 = 0. leftmosthigh.append(leftmax) leftmax = max(leftmax, x) rightmax = 0 res = 0 for i in xrange(len(height)-1, -1, -1): rightmosthigh = rightmax tmp = min(leftmosthigh[i], rightmosthigh) if tmp > height[i]: res += tmp - height[i] rightmax = max(rightmax, height[i]) return res
0 0
- leetcode -- Trapping Rain Water -- 重点
- LeetCode: Trapping Rain Water
- LeetCode : Trapping Rain Water
- [LeetCode] Trapping Rain Water
- [Leetcode] Trapping Rain Water
- [Leetcode] Trapping Rain Water
- [LeetCode]Trapping Rain Water
- LeetCode-Trapping Rain Water
- [leetcode] Trapping Rain Water
- [LeetCode] Trapping rain water
- Leetcode: Trapping Rain Water
- Leetcode:Trapping Rain Water
- [LeetCode] Trapping Rain Water
- <Leetcode>Trapping Rain Water
- Leetcode Trapping Rain Water
- leetcode Trapping Rain Water
- leetcode Trapping Rain Water
- LeetCode Trapping Rain Water
- C语言中简单的指针
- SQL Server 允许远程连接的解决方法
- Lab4 Authentication
- 本地yum源的创建,以及shell脚本安装.
- CSDN论坛网友写的一篇IOCP文章 -- 理解IOCP
- leetcode -- Trapping Rain Water -- 重点
- nginx源码分析--使用GDB调试
- DCT加密(Java((伪
- Android高德地图开发--读取解析KML文件并显示在地图上
- 文章标题
- 【大型网站技术实践】初级篇:借助LVS+Keepalived实现负载均衡
- 优化积分方法在Matlab中的实践
- Linux负载均衡软件LVS之一(概念篇)
- android 解码出来的视频frame数据,是如何一步步的传递到显示端的(使用 GPU offline 合成)