Test cases
|
|
Solution 1: accepted 111ms
|
|
Follow-up:
If the given numbers have a lot of duplicates, how to optimize the space use of the min stack?
We now maintain <number, the index of the number when it's added> in the min stack and we only pop it when the current index is equal or smaller than the index of the top element in the min stack. As a result, we also need a int count to track the index.