###### LeetCode225 Implemet Stack using Queues Java题解

Implement the following operations of a stack using queues.

• push(x) -- Push element x onto stack.
• pop() -- Removes the element on top of the stack.
• top() -- Get the top element.
• empty() -- Return whether the stack is empty.
Notes:
• You must use only standard operations of a queue -- which means only push to backpeek/pop from frontsize, and is emptyoperations are valid.
• Depending on your language, queue may not be supported natively. You may simulate a queue by using a list or deque (double-ended queue), as long as you use only standard operations of a queue.
• You may assume that all operations are valid (for example, no pop or top operations will be called on an empty stack).

class MyStack {

public void push(int x) {
queue.offer(x);
int i=queue.size()-1;
while(i>0)
{
queue.offer(queue.poll());
i--;
}

}

public void pop() {
queue.poll();
}

public int top() {
return queue.peek();
}

public boolean empty() {
return queue.isEmpty();

}
}

#### leetcode 225: Implement Stack using Queues

2015-06-19 01:00:54

#### LeetCode 225: Implement Stack using Queues

2015-06-13 14:58:28

#### [LeetCode-225] Implement Stack using Queues（两个队列实现栈）

2015-10-21 18:07:39

#### [leetcode-225]Implement Stack using Queues(c++)

2015-08-25 09:44:55

#### [leetcode: Python]225. Implement Stack using Queues

2017-05-12 12:54:44

#### LeetCode225:Implement Stack using Queues

2015-07-10 22:46:38

#### 【LeetCode】Implement Stack using Queues 解题报告

2015-06-14 10:35:53

#### 232. Implement Queue using Stacks [easy] (Python)

2016-06-04 23:32:59

#### LeetCode225—Implement Stack using Queues

2017-02-20 20:22:11

#### leetcode225 Implement Stack using Queues

2015-11-05 20:47:57

## 不良信息举报

LeetCode225 Implemet Stack using Queues Java题解