This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack { | |
constructor() { | |
this._items = []; | |
} | |
push(element) { | |
if (Array.isArray(element)) { | |
this._items.push(...element); | |
} else { | |
this._items.push(element); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Queue { | |
constructor() { | |
this._items = []; | |
} | |
enqueue(element) { | |
if (Array.isArray(element)) { | |
this._items.push(...element); | |
} else { | |
this._items.push(element); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Queue { | |
constructor() { | |
this._items = []; | |
} | |
enqueue(element) { | |
if (Array.isArray(element)) { | |
this._items.push(...element); | |
} else { | |
this._items.push(element); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
constructor(element) { | |
this.element = element; | |
this.next = null; | |
} | |
} | |
class LinkedList { | |
constructor() { | |
this._length = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
constructor(element) { | |
this.element = element; | |
this.next = null; | |
this.prev = null; | |
} | |
} | |
// 简单的优化过性能...... | |
class DoublyLinkedList { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Set { | |
constructor() { | |
this._items = {}; | |
} | |
add(value) { | |
if (!this.has(value)) { | |
this._items[value] = value; | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = [-2, 11, -4, 13, -5, -2]; | |
function max(data) { | |
let results = []; | |
for (let i = 0; i < data.length; i++) { | |
if (i === 0) { | |
results[i] = { | |
s: 0, | |
e: 1, |