Skip to content

Instantly share code, notes, and snippets.

@javi-aire
Created April 12, 2020 23:22
Show Gist options
  • Save javi-aire/81af0740e1eb44f10df1d64a26a7c849 to your computer and use it in GitHub Desktop.
Save javi-aire/81af0740e1eb44f10df1d64a26a7c849 to your computer and use it in GitHub Desktop.
Problem 10/30 of LeetCode 30-day challenge
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