美文网首页
BFS——127. 单词接龙

BFS——127. 单词接龙

作者: 含泪若笑 | 来源:发表于2020-09-02 10:39 被阅读0次

这道题也算是帮我有理了一下BFS的思路吧。大概就是:

1 new queue  visited的Set  步长

2 出队,做判断,加入set和queue,不断循环。

学习:

1 HashSet<String> words = new HashSet<>(wordList); 可以这样初始化hashset

2 char[] arr = str.toCharArray(); 与String s = String.valueOf(arr); 互相转换

3 这里的步长是每一个遍历一层之后加1;

代码:

https://github.com/hanleirx/LeetCode/blob/master/127.%20%E5%8D%95%E8%AF%8D%E6%8E%A5%E9%BE%99

相关文章

网友评论

      本文标题:BFS——127. 单词接龙

      本文链接:https://www.haomeiwen.com/subject/ouxnjktx.html