HowGraceU

Results 4 comments of HowGraceU

或许 next 的逻辑不应该放在队列里,队列应该做的只是保证根据**优先级和先入先出**来决定谁先出 ``` js class LazyMan { constructor(name) { this.name = name; this.queue = []; console.log(`Hi I am ${name}`); setTimeout(this.apply.bind(this)); } eat(something) { this.queue.push(() => console.log(`I am eating ${something}`));...

题目要求 尽量减少操作次数。 上面已经有人给出没有splice的双指针法了,不过用了交换数组的方法,复杂度为O(2n)(一般计算的时候常数忽略不计,所以可以当作O(n)) 举例 ``` js const arr = [1,0,2,3,4]; function moveZeroToLast(arr) { let index = 0; for (let i = 0, length = arr.length; i < length; i++) {...

no comment

这算是防君子不防小人么