leetcode python 042收集雨水
'''
给定n个非负整数表示每个条的宽度为1的高程图,计算下雨后能够捕获多少水。
例如,
鉴于[0,1,0,2,1,0,1,3,2,1,2,1],返回6。
这个题要先算出盛满水后的高程图,减去前者就是雨水。
盛水多高取决于左右最高的两处低的一方。
'''
l1=[0,1,0,2,1,0,1,3,2,1,2,1]
w=[]
for i in range(len(l1)):
w.append(min(max(l1[0:i+1]),max(l1[i:]))-l1[i])
print('收集雨水:',sum(w))
leetcode python 042收集雨水的更多相关文章
- [LeetCode] 407. Trapping Rain Water II 收集雨水 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] 42. Trapping Rain Water 收集雨水
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- Leetcode Python Solution(continue update)
leetcode python solution 1. two sum (easy) Given an array of integers, return indices of the two num ...
- Python零散收集:
Python零散收集 转义字符 描述 \(在行尾时) 续行符 \\ 反斜杠符号 \’ 单引号 \” 双引号 \a 响铃 \b 退格(Backspace) \e 转义 \000 空 \n 换行 \v 纵 ...
- python信息收集之子域名
python信息收集之子域名 主要是以下3种思路: 字典爆破 搜索引擎 第三方网站 0x00 背景知识 list Python内置的一种数据类型是列表:list是一种有序的集合. >>&g ...
- [转]Python 模块收集
Python 模块收集 转自:http://kuanghy.github.io/2017/04/04/python-modules Python | Apr 4, 2017 | python 工具 a ...
- 【LeetCode】042 Trapping Rain Water
题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, co ...
- LeetCode python实现题解(持续更新)
目录 LeetCode Python实现算法简介 0001 两数之和 0002 两数相加 0003 无重复字符的最长子串 0004 寻找两个有序数组的中位数 0005 最长回文子串 0006 Z字型变 ...
随机推荐
- centos卸载mysql
1.查看系统安装mysql rpm -qa|grep -i mysql 2.卸载 rpm -ev --nodeps mysql-community-release-el7-5.noarch 3.查询剩 ...
- Android 全局使用第三方字体
给APP全局设置字体主要分为两个方面来介绍 一.给原生界面设置第三方字体 1.准备工作-下载第三方字体:传送门 将文件放入工程assets目录下.(一般个人习惯单独命名一个文件夹放字体文件,也可直接放 ...
- unity 根据平板 或者 手机 确立横竖屏
/* ######### ############ ############# ## ########### ### ###### ##### ### ####### #### ### ####### ...
- C#Razor模板引擎简单使用
引用 install-package RazorEngine 使用 public class TestDemo { private string name; public int Age { get ...
- PowerShell自定义函数定义及调用
PowerShell是一种命令集,也有自己的语法定义及函数.本文主要介绍如何自定义powershell函数及如何调用,当初在写PowerShell自定义函数的时候查阅了很多资料都没找到如何调用自定义函 ...
- Gradle 依赖管理
依赖管理(在 build.gradle 中): 1.定义依赖仓库(repositories): Gradle 要求至少定义一个依赖仓库,依赖仓库可以是文件系统,也可以是中心服务器.最常用的是 jcen ...
- Nginx 安装及配置、负载均衡https网站及转发后页面js、css等路径找不到问题、更换证书导致问题解决
官网下载nginx:http://nginx.org/en/download.html 安装nginx编译环境:yum install -y gcc-c++ 安装pcre库解析正则:yum insta ...
- Activiti 工作流之所学所感(基本配置) DAY1
由于公司需求,最近在研究工作流,在此记录一下所学所感以备往后使用时候可以方便查询,有不足之处请各位大牛提点,下面直接进入主题. 下载activiti 所需资料 可以直接在官网上下载,也可以在我的网盘 ...
- wine安装稳定使用falsh播放器
1安装wine,wine安装使用网上自行查找 2.安装flash播放器.exe 下载附件的falsh播放相关.tar.gz,解压后得到 Flash.ocx (flash10 for windows的插 ...
- Map.putAll方法
import Java.util.HashMap; public class Map_putAllTest { public static void main(String[] args){ / ...