Skip to content

Commit

Permalink
155. Min Stack | Stack, Design
Browse files Browse the repository at this point in the history
Added README.md for the problem 155
  • Loading branch information
milan-r-shah committed Oct 2, 2020
1 parent 926b4e0 commit 90e4493
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions 0155_Min_Stack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 1,53 @@
### LeetCode
## Problem 155: Min Stack

https://leetcode.com/problems/min-stack/

Difficulty: Easy

---

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:

<pre>
<b>Input</b>
["MinStack","push","push","push","getMin","pop","top","getMin"]
[[],[-2],[0],[-3],[],[],[],[]]

<b>Output</b>
[null,null,null,null,-3,null,0,-2]

<b>Explanation</b>
MinStack minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
minStack.getMin(); // return -3
minStack.pop();
minStack.top(); // return 0
minStack.getMin(); // return -2
</pre>

<br>

**Constraints:**

- Methods `pop`, `top` and `getMin` operations will always be called on **non-empty** stacks.

<br>

**Related Topics:**
`Stack`, `Design`

---

**Useful Links:**
1. LeetCode 155. Min Stack (Algorithm Explained) - Nick White -- [video](https://youtu.be/WxCuL3jleUA)
2. C using two stacks, quite short and easy to understand -- [from LeetCode discussion](https://leetcode.com/problems/min-stack/discuss/49016/C++-using-two-stacks-quite-short-and-easy-to-understand)

0 comments on commit 90e4493

Please sign in to comment.