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 4e53da9 commit 0b5744eCopy full SHA for 0b5744e
animation-simulation/栈和队列/剑指Offer09用两个栈实现队列.md
@@ -58,6 +58,7 @@ class CQueue {
58
59
大家可以点击该链接[剑指 Offer 09. 用两个栈实现队列](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/)去实现一下,下面我们看代码。
60
61
+Java Code:
62
```java
63
class CQueue {
64
//初始化两个栈
@@ -89,3 +90,24 @@ class CQueue {
89
90
}
91
```
92
93
+JS Code:
94
+```javascript
95
+var CQueue = function() {
96
+ this.stack1 = [];
97
+ this.stack2 = [];
98
+};
99
+
100
+CQueue.prototype.appendTail = function(value) {
101
+ this.stack1.push(value);
102
103
104
+CQueue.prototype.deleteHead = function() {
105
+ if (!this.stack2.length) {
106
+ while(this.stack1.length) {
107
+ this.stack2.push(this.stack1.pop());
108
+ }
109
110
+ return this.stack2.pop() || -1;
111
112
+```
113
0 commit comments