Intuition
- Descending stack.
- When height[i] > top, pop stack and calculate the sum.
- How to calculate the sum: assume the height[i] is the border height of this region.
sum += height[i] - pop
save the second height and bar count. The actual border is height[i] and second, so minus the extra spaces(height[i] - second) * count
solution
|
|
problem
WA.
reason
When pop out the lower bars, I missed them in later calculation.
modification
Save the index instead of height. And the index need to be considered during calculation.
|
|