'''给定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))…
Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of water it is able to trap after raining. Note:Both m and n are less than 110. The height of each unit cell is greater tha…
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. The above elevation map is represented by a…
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of…
leetcode python solution 1. two sum (easy) Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution. Example: Given nums = [2, 7, 11, 15],…
题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. The above elevation map is represented…