leetcode Trapping Rain Water pthon
class Solution(object):
def trap(self,nums):
leftmosthigh = [0 for i in range(len(nums))]
leftmax=0
for i in range(len(nums)):
if nums[i] > leftmax:
leftmax=nums[i]
leftmosthigh[i] = leftmax
print leftmosthigh
sums=0
rightmax=0
for i in reversed(range(len(nums))):
print i
if nums[i] > rightmax:
rightmax = nums[i]
print 'i is',i,'rightmax is',rightmax
#current i less than it's two side, then it can trap
if min(rightmax,leftmosthigh[i] ) > nums[i]:
sums+=min(rightmax,leftmosthigh[i])-nums[i]
return sums
nums= [0,1,0,2,1,0,1,3,2,1,2,1]
obj=Solution()
rs=obj.trap(nums)
print rs

leetcode Trapping Rain Water pthon的更多相关文章
- [LeetCode] Trapping Rain Water II 收集雨水之二
Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevati ...
- [LeetCode] Trapping Rain Water 收集雨水
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- LeetCode: Trapping Rain Water 解题报告
https://oj.leetcode.com/problems/trapping-rain-water/ Trapping Rain WaterGiven n non-negative intege ...
- Leetcode: Trapping Rain Water II
Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevati ...
- [leetcode]Trapping Rain Water @ Python
原题地址:https://oj.leetcode.com/problems/trapping-rain-water/ 题意: Given n non-negative integers represe ...
- Leetcode Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- [LeetCode] Trapping Rain Water 栈
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- [LeetCode] Trapping Rain Water II 题解
题意 题目 思路 我一开始想的时候只考虑到一个结点周围的边界的情况,并没有考虑到边界的高度其实影响到所有的结点盛水的高度. 我们可以发现,中间是否能够盛水取决于边界是否足够高于里面的高度,所以这必然是 ...
- [Leetcode][Python]42: Trapping Rain Water
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 42: Trapping Rain Waterhttps://oj.leetc ...
随机推荐
- Performing a full database disaster recovery with RMAN
Performing a full database disaster recovery with RMAN1. Make the RMAN backup set pieces available.2 ...
- ORACLE表空间管理方式segment和extent
A permanent tablespace contains persistent schema objects. Objects in permanent tablespaces are stor ...
- C# Winform下载文件并显示进度条
private void btnDown_Click(object sender, EventArgs e) { DownloadFile("http://localhost:1928/We ...
- iOS开发那些事儿(五)Objective-C浅拷贝与深拷贝
浅拷贝:copy操作出来的对象指针直接指向模板的地址.即两个对象公用一块内存地址 #import <Foundation/Foundation.h> int main(int argc, ...
- mysql的高级用法
1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- 创建 备份 ...
- struts2中的方法过滤拦截器
方法过滤拦截器是只过滤指定的方法,如果使用针对action 的普通的过滤器则会过滤该action内部 所有方法.如果在一个action中同时有多个作为业务逻辑控制的方法存在 的话则会过滤所有的业务逻辑 ...
- centos 添加epel、remi仓库和ELRepo仓库
centos使用yum安装软件非常方便,yum会自动安装软件的相关依赖.但是centos自带的源仓库,软件相对老旧并且不太全,所以我们可以添加第三方仓库,可以安装较新的软件版本. epel是fedor ...
- 什么是web标准
Web Standards Standards是个复数,就知道他是有好几个标准或者规范组成的,分别是:结构规范 XML ,XHTML;表现规范 CSS;行为规范 DOM,ECMAScript; 上面是 ...
- Android02-Activity01
1.概念:活动是一种可以包含用户界面的组件, 主要用于和用户进行交互. 2.常见操作: 1.隐藏Activity的标题栏: @Override protected void onCreate ...
- DTU软硬件方案
经过周末的思考以及已有的经验,准备将DTU研发项目命名为QN100,确定了初步的软硬件方案,产品名称大家如果有好的名字欢迎提供. 硬件: 采用STM32F101RD为主处理器, ...