每日题单 · 2026-10-16
用法
每题先自己写 25 分钟(时间盒),卡住就找我要档位提示;做完把 [x] 勾上。 复盘题不写新笔记,直接在原文出处下方追加「二刷日期 + 一句话卡点」。
🆕 新题(codetop 前端岗频率榜)
🔁 复盘(vault 轮换池)
| 题目 | 难度 | 频率 | 备注 |
|---|---|---|---|
| 最长回文串 | — | — | 复盘 · 出处:GRD 字符串 |
| 无重复字符的最长子串 | 中等 | 122 | 复盘 · 出处:GRD 字符串 |
完成打卡
/**
* 四条 for 剥壳法(推荐默写版:4 个边界 + 4 句人话,Θ(m·n) / O(1))
* 二刷历程:首版用「四边界 + 方向机」独立 AC,补上空矩阵守卫后通过;
* 对照 [[54 螺旋矩阵]] 后定为记忆成本更低的剥壳版
* @param {number[][]} matrix
* @return {number[]}
*/
var spiralOrder = function (matrix) {
if (matrix.length === 0 || matrix[0].length === 0) return [];
const res = [];
let top = 0, bottom = matrix.length - 1; // 上下边界(行)
let left = 0, right = matrix[0].length - 1; // 左右边界(列)
while (top <= bottom && left <= right) {
for (let j = left; j <= right; j++) res.push(matrix[top][j]); // ① 上边:左 → 右
top++; // 上边扫完,边界往里收
for (let i = top; i <= bottom; i++) res.push(matrix[i][right]); // ② 右边:上 → 下
right--;
if (top <= bottom) { // 还有第二行才走回头路
for (let j = right; j >= left; j--) res.push(matrix[bottom][j]); // ③ 下边:右 → 左
bottom--;
}
if (left <= right) { // 还有第二列才走回头路
for (let i = bottom; i >= top; i--) res.push(matrix[i][left]); // ④ 左边:下 → 上
left++;
}
}
return res;
};- 新题 2:200. 岛屿数量(原题卡片见 LeetCode Hot100 反转链表与课程表)
/**
* @param {character[][]} grid
* @return {number}
*/
const dfs =(grid, i, j, x, y) => {
if(i<0 || j<0 || i>=y || j>=x || grid[i][j] === '0') {
return
}
grid[i][j] = '0'
dfs(grid, i+1, j, x, y)
dfs(grid, i-1, j, x, y)
dfs(grid, i, j+1, x, y)
dfs(grid, i, j-1, x, y)
}
var numIslands = function(grid) {
const y = grid.length
const x = grid[0].length
let res = 0
for(let i = 0; i < y; i++) {
for(let j = 0; j < x; j++) {
if(grid[i][j] === '1') {
res++
dfs(grid, i, j, x, y)
}
}
}
return res
};二刷卡点:递归深度是 n²,会爆栈
逻辑全对(示例 1/2、
1×1全水/全陆均通过),但实测全1的 n×n 网格递归深度精确等于 n²(n=5→25、n=50→2500、n=80→6400),本地 Node 在100×100全陆即RangeError: Maximum call stack size exceeded,而本题约束 m, n ≤ 300(外推约 90000 层)。 面试改法二选一:① 显式栈 / 队列(一份骨架,pop()是 DFS、queue[head++]是 BFS);② 四周套一圈'0'当哨兵边框,内层判断从 5 个条件压到 1 个(顺带不改入参、不爆栈)。flood fill 的方向顺序随便写,不像 54 螺旋矩阵 必须顺时针。
- 复盘 1
- 复盘 2