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 ...
随机推荐
- odbc连接数据库
using System; using System.Collections.Generic; using System.Text; using Console = System.Console; u ...
- HTML及CSS常用颜色英文词汇
黑色 银色 灰色 白色 茶色 红色 紫色 紫红 black silver gray white maroon red purple fuchsia #000000 #C0C0C0 #808080 #F ...
- sqlyog绿色破解版
http://pan.baidu.com/s/1mghyUrY 下载地址
- [Linked List]Linked List Cycle,Linked List Cycle II
一.Linked List Cycle Total Accepted: 85115 Total Submissions: 232388 Difficulty: Medium Given a linke ...
- mysql学习(五)-字段属性
字段属性: unsigned: 无符号类型,只能修饰数值类型: create table if not exists t1(id int unsigned); zerofill:前端填0 //只能修饰 ...
- php安全编程—sql注入攻击
php安全编程--sql注入攻击 定义 SQL注入攻击指的是通过构建特殊的输入作为参数传入Web应用程序,而这些输入大都是SQL语法里的一些组合,通过执行SQL语句进而执行攻击者所要的操作,其主要原因 ...
- C++vptr初始化时间
给出如下代码段: #include <iostream> #include "stdio.h" using namespace std; class A { publi ...
- WampServer下如何实现多域名配置
原文:WampServer下如何实现多域名配置 之前在学习跨域的时候,我写过一篇叫做WampServer下使用多端口访问的文章,默认的 localhost 采用的是 80 端口,能使用多端口访问的核心 ...
- jQuery粘性跟随滚动条滚动的导航栏源代码下载
jQuery粘性跟随滚动条滚动的导航栏源代码下载 作者:网页模板 大小:0.005MB 点击次数:3494 发布时间:2014-03-07 12:55 分享到:0 特效介绍 jQuery粘性跟随滚动条 ...
- eclipse中的两种Jre 及 Jre与Jdk的区别
分类: ——————————区分eclipse中的两种Jre———————- (Eclipse也是一个普通的Java程序,因此必须有一个JRE做为运行环境.如果你的机器上没有安装任何JRE(或者JDK ...