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的更多相关文章

  1. [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 ...

  2. [LeetCode] Trapping Rain Water 收集雨水

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  3. LeetCode: Trapping Rain Water 解题报告

    https://oj.leetcode.com/problems/trapping-rain-water/ Trapping Rain WaterGiven n non-negative intege ...

  4. 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 ...

  5. [leetcode]Trapping Rain Water @ Python

    原题地址:https://oj.leetcode.com/problems/trapping-rain-water/ 题意: Given n non-negative integers represe ...

  6. Leetcode Trapping Rain Water

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  7. [LeetCode] Trapping Rain Water 栈

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  8. [LeetCode] Trapping Rain Water II 题解

    题意 题目 思路 我一开始想的时候只考虑到一个结点周围的边界的情况,并没有考虑到边界的高度其实影响到所有的结点盛水的高度. 我们可以发现,中间是否能够盛水取决于边界是否足够高于里面的高度,所以这必然是 ...

  9. [Leetcode][Python]42: Trapping Rain Water

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 42: Trapping Rain Waterhttps://oj.leetc ...

随机推荐

  1. 爱加密亮相第十八届软博会,移动App安全引关注

    2014年5月29日至31日,2014年第十八届中国国际软件博览会在北京展览馆举行,此次软博会的主题为"软件引领信息消费,助力经济转型升级",充分展示软件业在促进信息消费.提升社会 ...

  2. android卸载反馈实现

    博客原地址:http://blog.csdn.net/wang_shaner/article/details/41543787 实现原理 fork分叉函数 fork分叉(分裂)函数可以创建一个新进程, ...

  3. Object-c学习之路七(oc字符串操作)

    // // main.m // NSString // // Created by WildCat on 13-7-25. // Copyright (c) 2013年 wildcat. All ri ...

  4. MySQL之终端(Terminal)管理数据库、数据表、数据的基本操作(转)

    MySQL有很多的可视化管理工具,比如“mysql-workbench”和“sequel-pro-”. 现在我写MySQL的终端命令操作的文章,是想强化一下自己对于MySQL的理解,总会比使用图形化的 ...

  5. log4j是什么

    一.什么是log4jLog4j 是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务器.NT的事 件记录器.UNIX S ...

  6. 无废话MVC入门教程二[第一个小Demo]

    mvc技术交流,欢迎加群: 本文目标 1.了解"模型"."视图"."控制器"的创建.调试和使用过程. 本文目录 1.创建模型 2.创建视图 ...

  7. hdu1711Number Sequence

    Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], .... ...

  8. js创建对象的方式 三种

    1. 使用直接量创建1个对象: var aobj = { x : 10, y : function(){ console.log("aobj--> "+this.x); } ...

  9. php输出json中文显示编码-解决办法

    $str = "中华人民共和国";$ar = array( "a" => "a0", "b" => &quo ...

  10. javascript 数据结构和算法读书笔记 > 第四章 栈

    1. 对栈的操作 栈是一种特殊的列表,栈中的元素只能通过列表的一端进行访问,即栈顶.类似于累起一摞的盘子,只能最后被放在上面的,最先能被访问到. 就是我们所说的后入先出(LIFO). 对栈主要有入栈p ...