diff --git a/src/leetcode/design.md b/src/leetcode/design.md index f936956..36db27a 100644 --- a/src/leetcode/design.md +++ b/src/leetcode/design.md @@ -1 +1,38 @@ -# Design \ No newline at end of file +# Design + ++ [Implement Queue using Stacks](#implement-queue-using-stacks) + +## Implement Queue using Stacks +https://leetcode.com/problems/implement-queue-using-stacks/ +```java +class MyStack { + Stack s1 = new Stack<>(); + Stack s2 = new Stack<>(); + public void push(int x) { + + while(!s1.isEmpty()){ + s2.push(s1.pop()); + } + + s1.push(x); + + while(!s2.isEmpty()){ + s1.push(s2.pop()); + } + + } + + public int pop() { + return s1.pop(); + } + + public int peek() { + return s1.peek(); + } + + public boolean empty() { + return s1.isEmpty(); + } +} + +``` \ No newline at end of file