目录
- 栈、队列(Stack、Queue)
-
- 栈
- 队列
- 面试题
-
- [844. Backspace String Compare](https://leetcode.com/problems/backspace-string-compare/)
- [232. Implement Queue using Stacks](https://leetcode.com/problems/implement-queue-using-stacks/)
- [225. Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues/)
- [20. Valid Parentheses](https://leetcode.com/problems/valid-parentheses/)
- [255. Verify Preorder Sequence in Binary Search Tree](https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree/)
栈、队列(Stack、Queue)
时间空间复杂度
栈
结构
队列
结构
面试题
844. Backspace String Compare
232. Implement Queue using Stacks
自己的解法:
class MyQueue {
Stack<Integer> in,out;
/** Initialize your data structure here. */
public MyQueue() {
in = new Stack<Integer>();
out = new Stack<Integer>();
}
/** Push element x to the back of queue. */
public void push(int x) {
in.push(x);
}
/** Removes the element from in front of queue and returns that element. */
public int pop() {
if(!out.empty()){
return out.pop();}
while(!in.empty()){
out.push(in.pop());
}
return out.pop();
}
/** Get the front element. */
public int pee