首发于 语雀@blueju

    https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/submissions/

    1. var CQueue = function () {
    2. this.inStack = []
    3. this.outStack = []
    4. };
    5. /**
    6. * @param {number} value
    7. * @return {void}
    8. */
    9. CQueue.prototype.appendTail = function (value) {
    10. this.inStack.push(value)
    11. };
    12. /**
    13. * @return {number}
    14. */
    15. CQueue.prototype.deleteHead = function () {
    16. if (this.outStack.length === 0) {
    17. if (this.inStack.length === 0) {
    18. return -1
    19. } else {
    20. this.inStack.forEach(item => {
    21. this.outStack.unshift(item)
    22. })
    23. this.inStack = []
    24. return this.outStack.pop()
    25. }
    26. } else {
    27. return this.outStack.pop()
    28. }
    29. };
    30. /**
    31. * Your CQueue object will be instantiated and called as such:
    32. * var obj = new CQueue()
    33. * obj.appendTail(value)
    34. * var param_2 = obj.deleteHead()
    35. */