28. 找出字符串中第一个匹配项的下标
题目链接:232. 用栈实现队列
225. 用队列实现栈
题目链接:225. 用队列实现栈
- 需要清楚java链表和Queue的接口,que.peek()是队首元素
class MyStack {
Queue<Integer> que;
public MyStack() {
que = new LinkedList<>();
}
public void push(int x) {
que.offer(x);
int size = que.size();
while(size-- > 1){
que.offer(que.poll());
}
}
public int pop() {
return que.poll();
}
public int top() {
return que.peek();
}
public boolean empty() {
return que.isEmpty();
}
}
/**
* Your MyStack object will be instantiated and called as such:
* MyStack obj = new MyStack();
* obj.push(x);
* int param_2 = obj.pop();
* int param_3 = obj.top();
* boolean param_4 = obj.empty();
*/