Skip to content

Commit

Permalink
Update 0286. 墙与门.md
Browse files Browse the repository at this point in the history
  • Loading branch information
itcharge committed Jan 9, 2022
1 parent bfa1704 commit 8b0bab1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Solutions/0286. 墙与门.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

## 题目大意

给定一个 m * n 的二维网络 rooms。其中每个元素有三种初始值:
给定一个 `m * n` 的二维网络 `rooms`。其中每个元素有三种初始值:

- `-1` 表示墙或者障碍物
- `0` 表示一扇门
- `INF` 表示为一个空的房间。这里用 $2^{31} = 2147483647$ 表示 `INF`。通往门的距离总是小于 $2^{31}$。

要求:给每个空房间填上该房间到最近的门的距离,如果无法到达们,则填 INF。
要求:给每个空房间填上该房间到最近的门的距离,如果无法到达门,则填 `INF`

## 解题思路

从每个表示门开始,使用宽度优先搜索去照门。因为宽度优先搜索保证我们在搜索 dist + 1 距离的位置时,距离为 dist 的位置都已经搜索过了。所以每到达一个房间的时候一定是最短距离。
从每个表示门开始,使用广度优先搜索去照门。因为广度优先搜索保证我们在搜索 `dist + 1` 距离的位置时,距离为 `dist` 的位置都已经搜索过了。所以每到达一个房间的时候一定是最短距离。

## 代码

Expand Down

0 comments on commit 8b0bab1

Please sign in to comment.