Analysis:
using a stack to keep the always increasing order of the results.
using a set to track the elements containing current answer result.
The key point is to ensure the order by comparing the current number with the tail number in the stack only if the counter of it is large than 1
Time Complexity:
- O(n)
Space Complexity:
- O(n)
Code
1 | class Solution(object): |