[LeetCode], solution, non-code implementation
Posted 心中有阳光
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode], solution, non-code implementation相关的知识,希望对你有一定的参考价值。
42. Trapping Rain Water
we need to find how many waters can each block[i] trap. So we need to find the left peak from block_0 to block[i-1] and find the right peak from block[i+1] to block[n-1]. See the following pseudo-code:
total_water = 0;
for i = 0 to n-1:
Lmax = Max(h[0], h[1], ... h[i-1]);
Rmax = Max(h[i+1], h[i+2], ... h[n-1]);
water_and_building = Min(Lmax, Rmax);
wi = water_and_building - h[i]; // the building has some height
total_water += wi;
return total_water;
以上是关于[LeetCode], solution, non-code implementation的主要内容,如果未能解决你的问题,请参考以下文章
Leetcode solution 124: Binary Tree Maximum Path Sum
Leetcode 665. Non-decreasing Array
LeetCode338. Counting Bits (2 solutions)