Skip to content

Commit

Permalink
Update 0752. 打开转盘锁.md
Browse files Browse the repository at this point in the history
  • Loading branch information
itcharge committed Jan 9, 2022
1 parent 8b0bab1 commit 08f54ff
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Solutions/0752. 打开转盘锁.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

## 题目大意

有一把带有四个数字的密码锁,每个位置上有 0~910 个数字。每次只能将其中一个位置上的数字转动一下。可以向上转,也可以向下转。比如:1 -> 22 -> 1。
有一把带有四个数字的密码锁,每个位置上有 `0` ~ `9``10` 个数字。每次只能将其中一个位置上的数字转动一下。可以向上转,也可以向下转。比如:`1 -> 2``2 -> 1`

密码锁的初始数字为:`0000`。现在给定一组表示死亡数字的字符串数组 deadends,和一个带有四位数字的目标字符串 target。
密码锁的初始数字为:`0000`。现在给定一组表示死亡数字的字符串数组 `deadends`,和一个带有四位数字的目标字符串 `target`

如果密码锁转动到 deadends 中任一字符串状态,则锁就会永久锁定,无法再次旋转。
如果密码锁转动到 `deadends` 中任一字符串状态,则锁就会永久锁定,无法再次旋转。

要求:给出最小的选择次数,使得锁的状态由 `0000` 转动到 target。
要求:给出最小的选择次数,使得锁的状态由 `0000` 转动到 `target`

## 解题思路

使用宽度优先搜索遍历,将`0000` 状态入队。
使用广度优先搜索遍历,将`0000` 状态入队。

- 将队列中的元素出队,判断是否为死亡字符串
- 如果为死亡字符串,则跳过该状态,否则继续执行。
Expand Down

0 comments on commit 08f54ff

Please sign in to comment.