음..성능이..
class MinStack {
/** initialize your data structure here. */
class Node{
int val;
Node next;
Node(int val){
this.val = val;
this.next = null;
}
}
Node top = null;
public MinStack() {
}
public void push(int x) {
Node node = new Node(x);
node.next = top;
top = node;
}
public void pop() {
top = top.next;
}
public int top() {
return top.val;
}
public int getMin() {
Node node = top;
int min = node.val;
while(node != null){
if(min > node.val){
min = node.val;
}
node = node.next;
}
return min;
}
}
'개발 > CodingTest' 카테고리의 다른 글
LeetCode - Shuffle the array (0) | 2020.06.26 |
---|---|
Hackerrank - Utopian Tree (0) | 2020.06.25 |
Hacckerrank - The Hurdle Race (0) | 2020.06.25 |
Hacckerrank - Halloween Sale (0) | 2020.06.25 |
Hackerrank - Prime Checker (0) | 2020.06.05 |