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字型变 ...
随机推荐
- Oracle使用——数据泵导入导出数据库——impdp/expdp使用
使用前提 EXPDP和IMPDP只可以在Oracle服务端使用. EXP导出的文件只可以使用IMP导入,不适用于IMPDP导入文件:EXPDP导出的文件只可以使用IMPDP导入,而不适用于IMP导出文 ...
- Markdown简记
一篇好的博客文档离不开一个优秀的编辑器.借此篇文章介绍一下编写该博客markdown的语法,方便大家写出更好更漂亮的文档.重点是点击左上角的Github链接,有主题源码哦 一篇好的博客文档离不开一个优 ...
- Class.jsp
<%@page import="java.util.Random"%> <%@ page language="java" contentTyp ...
- CSS scroll-behavior和JS scrollIntoView让页面滚动平滑
转自 https://www.zhangxinxu.com/wordpress/2018/10/scroll-behavior-scrollintoview-%E5%B9%B3%E6%BB%91%E6 ...
- Hadoop入门
一.Hadoop是什么 1)Hadoop是一个由Apache基金会所开发的分布式系统基础架构. 2)Hadoop主要解决,海量数据的存储和海量数据的分析计算问题. 3)广义上来说,Hadoop通常是指 ...
- 在CentOS6.9上Shell脚本定时释放内存cache
一.写Shell脚本 mkdir -p /var/script/ vim /var/script/freemem.sh 写入以下Shell脚本: #!/bin/bash # 当前已使用的内存大小 us ...
- Python自学:第三章 使用方法sort( )对列表进行永久性排序
cars = ["bmw", "audi", "toyota", "subaru"] cars.sort() print ...
- scrapy 中crawlspider 爬虫
爬取目标网站: http://www.chinanews.com/rss/rss_2.html 获取url后进入另一个页面进行数据提取 检查网页: 爬虫该页数据的逻辑: Crawlspider爬虫类: ...
- 『高性能模型』卷积复杂度以及Inception系列
转载自知乎:卷积神经网络的复杂度分析 之前的Inception学习博客: 『TensorFlow』读书笔记_Inception_V3_上 『TensorFlow』读书笔记_Inception_V3_下 ...
- python 中的 yield 究竟为何物?生成器和迭代器的区别?
当你突然看到别人的代码中出现了一个好像见过但又没用过的关键词 比如 yield ,你是否会觉得这段代码真是高大上呢? 或许只有我这种小白才会这样子觉得,就在刚刚,我就看见了别人的代码中的yield,觉 ...