剑指offer09 补充js版解法

pull/20/head
daluozha 2021-04-27 18:13:37 +08:00
parent 4e53da9e3e
commit 0b5744e2fa
1 changed files with 22 additions and 0 deletions

View File

@ -58,6 +58,7 @@ class CQueue {
[ Offer 09. ](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/)去实现一下,下面我们看代码。
Java Code:
```java
class CQueue {
//初始化两个栈
@ -89,3 +90,24 @@ class CQueue {
}
```
JS Code:
```javascript
var CQueue = function() {
this.stack1 = [];
this.stack2 = [];
};
CQueue.prototype.appendTail = function(value) {
this.stack1.push(value);
};
CQueue.prototype.deleteHead = function() {
if (!this.stack2.length) {
while(this.stack1.length) {
this.stack2.push(this.stack1.pop());
}
}
return this.stack2.pop() || -1;
};
```