返回题库

骑士的最少移动次数

Minimum Knight Moves

专题
Algorithmic Programming / 算法编程
难度
L3
来源
Citadel

题目详情

问题:骑士的最少移动次数

考察:广度优先搜索

来源:DSA Prep / Citadel

链接:https://leetcode.com/problems/minimum-knight-moves

英文原题

Problem: Minimum Knight Moves

Patterns: Breadth-First Search

Recency: 2yr

Link: https://leetcode.com/problems/minimum-knight-moves

Source: https://www.dsaprep.dev/blog/citadel-coding-interview-questions/

解析

思路:棋盘关于坐标轴和对角线对称,可把目标转到第一象限。用 BFS 从 (0,0) 搜索,限制到目标附近的合理边界;也可用数学递推处理大坐标。

复杂度:BFS 状态数与目标距离平方相关;常见约束下可接受,空间同状态数。


英文解析

Approach: Use symmetry to move the target into the first quadrant, then run BFS from `(0,0)` with a bounded search region slightly beyond the target. Each BFS layer is one knight move, so the first visit to the target is optimal.

Complexity: Time and space are proportional to the number of visited board states.