first thought
- Using monotonic stack(I’m not sure whether this translation is correct).
- Monotonic stack is calculate the sum when popping out a number, we need to calculate the sum of all the numbers which can be seen by others. So this stack is a descending stack.
- When popping out a number, all the numbers in the stack is larger than it, which means they can see this number. So just add up the size of the stack.
- Remember to clear the stack.
solution
Because the input and output in POJ is so weird, so just show the solution.
|
|