几个笑话 -- 和老婆的闺蜜聊天# Joke - 肚皮舞运动
f*g
1 楼
leecode那道min stack题目,哪位牛人帮看看
class MinStack {
private Stack st = new Stack();
private Stack min = new Stack();
public void push(int num) {
st.push(num);
if (min.isEmpty() || num <= min.peek()) {
min.push(num);
}
}
public void pop() {
if (st.peek() == min.peek()) {
min.pop();
}
st.pop();
}
public int top() {
return st.peek();
}
public int getMin() {
return min.peek();
}
}
Input: push(512),push(-1024),push(-1024),push(512),pop,getMin,pop,getMin,
pop,getMin
Output: [-1024,-1024,-1024]
Expected: [-1024,-1024,512]
class MinStack {
private Stack
private Stack
public void push(int num) {
st.push(num);
if (min.isEmpty() || num <= min.peek()) {
min.push(num);
}
}
public void pop() {
if (st.peek() == min.peek()) {
min.pop();
}
st.pop();
}
public int top() {
return st.peek();
}
public int getMin() {
return min.peek();
}
}
Input: push(512),push(-1024),push(-1024),push(512),pop,getMin,pop,getMin,
pop,getMin
Output: [-1024,-1024,-1024]
Expected: [-1024,-1024,512]