Day10 栈与队列
我的思路:
(偷偷用了List接口方法(好像在偷懒
解答:
class MyQueue {
List list = new ArrayList();
public MyQueue() {
}
public void push(int x) {
list.add(x);
}
public int pop() {
Object obj = list.remove(0);
return (Integer) obj;
}
public int peek() {
return (Integer)list.get(0);
}
public boolean empty() {
return list.isEmpty();
}
}
我的思路:
再次偷懒(没时间了QAQ
解答:
class MyStack {
List list = new ArrayList();
public MyStack() {
}
public void push(int x) {
list.add(0, x);
}
public int pop() {
return (Integer)list.remove(0);
}
public int top() {
return (Integer)list.get(0);
}
public boolean empty() {
return list.isEmpty();
}
}