publicclassSolution {publicinttrap(int[] A) {if(A.length < 3)return0;intres = 0;intl = 0, r = A.length - 1;//找出可以盛水的边界while(l < r && A[l] <= A[l + 1]) l++;while(l < r && A[r] <= A[r - 1]) r--;while(l <r) {intl
public: inttrapRainWater(vector<vector<int>>& heightMap) { if(heightMap.empty())return0; intm = heightMap.size(), n = heightMap[0].size(), res = 0, mx = INT_MIN; priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> q; vector<vector<bool>> visited...
[Image text](http://www.leetcode.com/static/images/problemset/rainwatertrap.png) 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 rain water (blue section) are being trapped. Thanks Marcos for contributing this image!
42. 接雨水 - 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 示例 1: [https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/10/22/rainwatertrap.png] 输入:height = [0,1,0,2,1,0,1,3,2,1,2,1] 输出
Code: 1classSolution {2public:3inttrapRainWater(vector<vector<int>>&heightMap) {4intm =heightMap.size();5if(m ==0)return0;6intn = heightMap[0].size();7if(n ==0)return0;8priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;9vector<vector<bool>> vis...
The article tries to explain leetcode 407. There is no satisfactory explanation online and honestly speaking I couldn't be convinced by my answer, either. Problem: Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume...