Analysis
- Stack can be used here to store the elements, one ‘#’ for one element and two ‘#’. And check if there is one ‘#’ remains in the stack, which means this is a valid pre-order
Time Complexity
- O(n)
Space Comlexity
- O(n)
Code
1 | class Solution(object): |