herrDeng網內搜尋

自訂搜尋

Ads

2024年4月12日 星期五

python c++用monotonic stack解 Leetcode難題42 trapping rain water並附pyplot繪直方圖解說


Python c++用monotonic stack解 Leetcode難題42 trapping rain water並附pyplot繪直方圖解說
想法是使用索引 m 的單調堆疊來找到右牆height[r]和左牆height [l];計算此區域高於底部 height[m]的水量應為min(height[r]-height[m], height[l]-height[m])*(r-l-1) 
---
python c++ uses monotonic stack to solve Leetcode problem 42 trapping rain water with explanation of histogram drawing with pyplot
The idea is using monotonic stack for index m to find the right wall height[r] & left wall height[l]; this region should has water amount above the bottom height[m] of min(height[r]-height[m], height[l]-height[m])*(r-l-1)

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章