We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0d03884 commit 44eb607Copy full SHA for 44eb607
src/stacks-and-queues/queue-via-stack.js
@@ -11,16 +11,13 @@ class QueueViaStack {
11
}
12
13
remove() {
14
- while(this.stack1.peek()){
15
- this.stack2.push(this.stack1.pop());
+ if(!this.stack2.peek()){
+ while(this.stack1.peek()){
16
+ this.stack2.push(this.stack1.pop());
17
+ }
18
- const first = this.stack2.pop();
19
- while(this.stack2.peek()){
20
- this.stack1.push(this.stack2.pop());
21
- }
22
-
23
- return first;
+ return this.stack2.pop();
24
25
26
0 commit comments