[Stack] Min Stack

2021. 2. 9. 23:13프로그래밍-코딩테스트/LeetCode

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.

stack을 구현하는 전형적인 문제다

자바스크립트로 구현하는 prototype 메소드는 this를 이용한다.