← 返回 meta 的题目列表Maze / Grid Navigation with Multiple Test Cases
类型:online_judge
Given a 2D maze grid where:
0 is an empty cell
1 is a wall/obstacle
S is the unique start
T is the unique target
You will implement functionality in steps (multiple test cases). A common first milestone (e.g., first 4 tests) is:
Implement a function that returns the shortest number of steps from S to T using 4-directional moves (up/down/left/right), without leaving the grid or passing through walls.
If T is unreachable, return -1.
Input
An m x n character matrix / list of strings grid
Output
An integer: the shortest steps from S to T, or -1
Constraints
1 <= m, n <= 200
grid contains only 0/1/S/T
Example
Input:
S001
0001
0100
100T
Output:
6
Example
Input
S001
0001
0100
100T
Output
6