每日题单 · 2026-09-22

用法

每题先自己写 25 分钟(时间盒),卡住就找我要档位提示;做完把 [x] 勾上。 复盘题不写新笔记,直接在原文出处下方追加「二刷日期 + 一句话卡点」。

🆕 新题(codetop 前端岗频率榜)

题目难度频率状态
112. 路径总和简单31🔁(已刷过,重做)
21. 合并两个有序链表简单30🔁(已刷过,重做)

🔁 复盘(vault 轮换池)

题目难度频率备注
最接近原点的 K 个点——复盘 · 出处:GRD 堆
任务调度器——复盘 · 出处:GRD 堆

完成打卡

/**
 * 递归(差值下传法)/ 叶子节点判定与短路剪枝
 * @param {TreeNode} root
 * @param {number} targetSum
 * @return {boolean}
 */
var hasPathSum = function(root, targetSum) {
    if(root === null) return false
    if(root.left === null && root.right === null) {
        return targetSum === root.val
    }
    const reminding = targetSum - root.val
    return hasPathSum(root.left, reminding) || hasPathSum(root.right, reminding)
};
/**
 * 虚拟头节点(Dummy Head)+ 双指针穿针引线 / 短路拼接剩余链表
 * @param {ListNode} list1
 * @param {ListNode} list2
 * @return {ListNode}
 */
var mergeTwoLists = function(list1, list2) {
    const dummy = new ListNode()
    let p = dummy, p1 = list1, p2 = list2
    while(p1 && p2) {
        if(p1.val < p2.val) {
            p.next = p1
            p1 = p1.next
        } else {
            p.next = p2
            p2 = p2.next
        }
        p = p.next
    }
    p.next = p1 || p2
    return dummy.next
};
/**
 * 大顶堆容量维护 K / 超出踢出堆顶保留最近 K 个
 * @param {number[][]} points
 * @param {number} k
 * @return {number[][]}
 */
var kClosest = function (points, k) {
    const heap = new Maxheap()          // 最大堆:按点的平方距离比较
 
    for (let point of points) {
        heap.insert(point)
        if (heap.size() > k) {
            heap.pop()                  // 超容量,踢掉最远的(堆顶)
        }
    }
    return heap.heap                    // 堆里剩的就是最近的 K 个
}
 
class Maxheap {
    constructor() {
        this.heap = []
    }
    parentIndex(index) {
        return (index - 1) >> 1
    }
    leftIndex(index) {
        return index * 2 + 1
    }
    rightIndex(index) {
        return index * 2 + 2
    }
    dist([x, y]) {
        return x * x + y * y
    }
    swap(x, y) {
        [this.heap[x], this.heap[y]] = [this.heap[y], this.heap[x]]
    }
    needChange(x, y) {
        return this.dist(this.heap[x]) < this.dist(this.heap[y])
    }
    size() {
        return this.heap.length
    }
    insert(point) {
        this.heap.push(point)
        this.shiftUp(this.size() - 1)
    }
    pop() {
        this.heap[0] = this.heap.pop()
        this.shiftDown(0)
    }
    shiftUp(index) {
        if (index === 0) return
        let pi = this.parentIndex(index)
        if (this.needChange(pi, index)) {
            this.swap(pi, index)
            this.shiftUp(pi)
        }
    }
    shiftDown(index) {
        let li = this.leftIndex(index)
        let ri = this.rightIndex(index)
        if (li < this.size() && this.needChange(index, li)) {
            this.swap(index, li)
            this.shiftDown(li)
        }
        if (ri < this.size() &&this.needChange(index, ri)) {
            this.swap(index, ri)
            this.shiftDown(ri)
        }
    }
}
  • 复盘 2