LeetCode常见题型——广度优先搜索

1. 算法思想

广度优先搜索(breadth-first search, BFS) 是层层遍历的。因此,需要用先入先出的队列。

BFS常常用来处理最短路径问题。

DFS和BFS都可以处理可达性问题。DFS可以使用递归,但容易栈溢出,故DFS递归在实际工程中不常用。

2. 常见题型

LeetCode-934. Shortest Bridge [C++][Java]_贫道绝缘子的博客-CSDN博客You may change0's to1's to connect the two islands to formone island. Returnthe smallest number of0's you must flip to connect the two islands.https://blog.csdn.net/qq_15711195/article/details/123286958LeetCode-127. Word Ladder [C++][Java]_贫道绝缘子的博客-CSDN博客Atransformation sequencefrom wordbeginWordto wordendWordusing a dictionarywordListis a sequence of wordsbeginWord -> s1-> s2-> ... -> sk , return shortest sequence length.https://blog.csdn.net/qq_15711195/article/details/122800843LeetCode-126. Word Ladder II [C++][Java]_贫道绝缘子的博客-CSDN博客Given two words,beginWordandendWord, and a dictionarywordList, returnall theshortest transformation sequencesfrombeginWordtoendWord, or an empty list if no such sequence exists. Each sequence should be returned as a list of the words[beginWord,https://blog.csdn.net/qq_15711195/article/details/122814072

LeetCode-310. Minimum Height Trees [C++][Java]_贫道绝缘子的博客-CSDN博客When you select a nodexas the root, the result tree has heighth. Among all possible rooted trees, those with minimum height (i.e.min(h)) are calledminimum height trees(MHTs). Returna list of allMHTs'root labels.https://blog.csdn.net/qq_15711195/article/details/123300686

LeetCode-637. Average of Levels in Binary Tree [C++][Java]_贫道绝缘子的博客-CSDN博客Given therootof a binary tree, returnthe average value of the nodes on each level in the form of an array. Answers within10-5of the actual answer will be accepted.https://blog.csdn.net/qq_15711195/article/details/126321340

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贫道绝缘子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值