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 ...
随机推荐
- L9-2.安装mysql数据库
二.安装mysql 1.检查是否安装了mysql 2.安装cmake 输入gmake: make install 安装依赖的软件包: 新建用户权限等: 解压 安装 安装: 安装成功. 安装后调整: v ...
- UILabel头文件常见属性
text : default is nil 文本属性,默认值是 nil @property(nullable, nonatomic,copy) NSString *text; font : defau ...
- [Linked List]Remove Duplicates from Sorted List
Total Accepted: 90247 Total Submissions: 254602 Difficulty: Easy Given a sorted linked list, delete ...
- jQuery获取iframe的document对象
$(function() { var result = $('#myframe').prop('contentWindow').document; console.log(result); }); 这 ...
- 一个可以拓展的垂直多级导航栏 Demo
大四党忙忙碌碌找工作,博客荒废久矣,可谓:终日昏昏醉梦间,忽闻春尽强登山.因过竹院逢僧话,偷得浮生半日闲. 这是个垂直的导航栏,可以有无限多层的子级菜单,看代码注释就够了: <!DOCTYPE ...
- web2py官方文档翻译
00前言 我相信能够轻松地构建高质量增长的web应用程序是至关重要的一个自由和开放的社会.这可以防止玩家最大的垄断信息的流通. 因此我从2007年开始web2py项目,主要是作为一种教学工具与简化we ...
- Eclipse配色插件
1.打开Help -- Eclipse Marketplace 2.搜索Eclipse Color Theme,点击Install 3.安装完成后点击Window -- Preference -- A ...
- NetworkManager——Linux强大的网络管理工具
NetworkManager服务:NetworkManager - Linux Networking made Easy NetworkManager简介:NetworkManager由一个管理系统网 ...
- 8 个优秀的 Linux 图形图像及色彩工具
8 个优秀的 Linux 图形图像及色彩工具 1. 硬件色彩分析器LPROF LPROF 是一个用于创建设备兼容,如相机.扫描仪.显示器的ICC兼容型材的颜色分析器.这些配置提供跨设备的色彩一致性.他 ...
- cnn softmax regression bp求导
内容来自ufldl,代码参考自tornadomeet的cnnCost.m 1.Forward Propagation convolvedFeatures = cnnConvolve(filterDim ...