Difficult:Hard
題目
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.
翻譯
給定 n 個非負整數,表示每個條的寬度為 1 的高程圖,計算下雨後它可以捕獲多少水。
範例
Example 1:
1 | Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] |
Example 2:
1 | Input: height = [4,2,0,3,2,5] |
解題思路
1.左右邊比較大小,較小的一方往前移動。
Solution
Code 1 :
1 | var trap = function(height) { |
Code 2 :
1 | var trap = function (height) { |