forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_225.java
41 lines (32 loc) · 927 Bytes
/
_225.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.fishercoder.solutions;
import java.util.LinkedList;
import java.util.Queue;
public class _225 {
public static class Solution1 {
class MyStack {
Queue<Integer> q;
public MyStack() {
q = new LinkedList();
}
// Push element x onto stack.
public void push(int x) {
q.offer(x);
for (int i = 1; i < q.size(); i++) {
q.offer(q.remove());
}
}
// Removes the element on top of the stack.
public int pop() {
return q.poll();
}
// Get the top element.
public int top() {
return q.peek();
}
// Return whether the stack is empty.
public boolean empty() {
return q.isEmpty();
}
}
}
}