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
每次放heap里面放点的时候,如果当前点小于桶边的点,要放当前点的坐标,桶边点的高度,因为是按照最高高度装水的。 publicclassSolution {publicinttrapRainWater(int[][] heightMap) {if(heightMap ==null|| heightMap.length == 0) {return0; }intm =heightMap.length;intn = heightMap[0].length;int[]...
classSolution {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>> vis...
遍历它前后左右并压入Q做候选,如果邻居中找到了比当前块还低的块,意味着水位mx - height(neighbor)就是neighbor能蓄的水量。 /** @lc app=leetcode id=407 lang=cpp** [407] Trapping Rain Water II*/// @lc code=startclassSolution{public:inttrapRainWater(vector<vector<int>>&heightMap){if(heightMa...
class Solution: """ @param heights: a list of integers @return: a integer """ def trapRainWater(self, heights): if not heights: return 0 left_max = [] curt_max = -sys.maxsize for height in heights: curt_max = max(curt_max, height) left_max.append(curt_max) right_max = []...
https://leetcode.com/problems/trapping-rain-water-ii/discuss/89461/Java-solution-using-PriorityQueuehttps:///watch?v=cJayBq38VYwclassSolution {publicinttrapRainWater(int[][] heightMap) {if(heightMap ==null|| heightMap.length <= 1 || heightMap[0].length <= 1) {return0; ...
[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!
public int trapRainWater(int[][] heightMap) { if (heightMap == null || heightMap.length == 0 || heightMap[0].length == 0) return 0; PriorityQueue<Cell> queue = new PriorityQueue<>(1, new Comparator<Cell>(){ public int compare(Cell a, Cell b) { ...
publicclassSolution{publicclassCell{introw;intcol;intheight;publicCell(introw,intcol,intheight){this.row=row;this.col=col;this.height=height;}}publicinttrapRainWater(int[][]heights){if(heights==null||heights.length==0||heights[0].length==0)return0;PriorityQueue<Cell>queue=newPriorityQueue<>(...