Created
April 12, 2020 23:22
-
-
Save javi-aire/81af0740e1eb44f10df1d64a26a7c849 to your computer and use it in GitHub Desktop.
Problem 10/30 of LeetCode 30-day challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MinStack { | |
constructor() { | |
this.items = []; | |
} | |
push(item) { | |
this.items.push(item); | |
} | |
pop() { | |
this.items.pop(); | |
} | |
top() { | |
return this.items[this.items.length-1]; | |
} | |
getMin() { | |
let min = this.items[0]; | |
for(let i = 1; i< this.items.length; i++) { | |
let item = this.items[i]; | |
if(item < min) { | |
min = item; | |
} | |
} | |
return min; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment