Stack2 LeetCode. Min Stack Problem: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. getMin() -- Retrieve the minimum element in the stack. Example 1: -Summary- Use tuple to save the minimum value and the current value of the stack. class MinStack: def __ini.. 2020. 6. 26. LeetCode 5. Valid Parentheses [Strings, Stack] Problem: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid. Example 1: Input: "()" Output: true Example 2: Input: "()[]{}" Output: true Exa.. 2020. 6. 12. 이전 1 다음