-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyStack.java
More file actions
38 lines (30 loc) · 759 Bytes
/
Copy pathMyStack.java
File metadata and controls
38 lines (30 loc) · 759 Bytes
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
package leetcode.easy.page2;
import java.util.ArrayDeque;
import java.util.Deque;
/**
* @author Kyle
* @create 2018/9/22 23:07
*/
public class MyStack {
private Deque<Integer> deque;
/** Initialize your data structure here. */
public MyStack() {
deque = new ArrayDeque<>();
}
/** Push element x onto stack. */
public void push(int x) {
deque.addLast(x);
}
/** Removes the element on top of the stack and returns that element. */
public int pop() {
return deque.pollLast();
}
/** Get the top element. */
public int top() {
return deque.getLast();
}
/** Returns whether the stack is empty. */
public boolean empty() {
return deque.isEmpty();
}
}