问题:
代码:
class Solution {
public int openLock(String[] deadends,String target){
Set deadendsSet =new HashSet<>();
for(String str:deadends){
deadendsSet.add(str);
}
//如果“0000”在死亡字符串中,则永远到达不了
if(deadendsSet.contains("0000"))
return -1;
//初始化队列
Queue que=new linkedList<>();
que.offer("0000");
//加标记,已经搜索过的字符串不需要再次搜索
Set book=new HashSet<>();
book.add("0000");
int step=0;
while(! que.isEmpty()){
int n=que.size();
//从上一步转化之后的字符串都需要进行验证和转换
for (int i = 0; i
运行结果:



