Skip to content

Commit ee2f2a7

Browse files
committed
Runtime: 1 ms (Top 34.13%) | Memory: 42.2 MB (Top 19.29%)
1 parent 5971369 commit ee2f2a7

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1+
// Runtime: 1 ms (Top 34.13%) | Memory: 42.2 MB (Top 19.29%)
12
class MyStack {
2-
3+
34
Queue<Integer> queue = null;
4-
5+
56
public MyStack() {
6-
queue = new LinkedList<>();
7+
queue = new LinkedList<>();
78
}
8-
9+
910
public void push(int x) {
10-
11-
Queue<Integer> tempQueue = new LinkedList<>();
12-
tempQueue.add(x);
13-
11+
12+
Queue<Integer> tempQueue = new LinkedList<>();
13+
tempQueue.add(x);
14+
1415
while(!queue.isEmpty()){
1516
tempQueue.add(queue.remove());
1617
}
17-
18+
1819
queue = tempQueue;
19-
20+
2021
}
21-
22+
2223
public int pop() {
2324
return queue.remove();
2425
}
25-
26+
2627
public int top() {
27-
return queue.peek();
28+
return queue.peek();
2829
}
29-
30+
3031
public boolean empty() {
3132
return queue.isEmpty();
3233
}
33-
}
34+
}

0 commit comments

Comments
 (0)