What is the advantage of using stack DS?


  • 0
    E

    Hello,

    I'm just curious about the "stack" tag of this question.
    For me the intuitive solution (and optimal) is the one has been posted several times.
    (Search from left to right while maintaining the max height. O(n) time, O(1) space)
    Does anyone know the solution using stack that might be better than the one above?

    Thanks


  • 0
    J

    Not much. First, I think it is interesting to see different solutions. And maybe you'll want to present a dynamic illustration with different methods to fill the containers. The one using a stack is more natural for such illustration.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.