mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Anonymous inner classes create generic instances that display the dec… (#627)
* Anonymous inner classes create generic instances that display the declared type * Update TreeNode.java * Update binary_tree_bfs.java * Update graph_bfs.java --------- Co-authored-by: zongjianwei <zongjianwei@meituan.com> Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@ -13,7 +13,8 @@ public class binary_tree_bfs {
|
||||
/* 层序遍历 */
|
||||
static List<Integer> levelOrder(TreeNode root) {
|
||||
// 初始化队列,加入根节点
|
||||
Queue<TreeNode> queue = new LinkedList<>() {{ add(root); }};
|
||||
Queue<TreeNode> queue = new LinkedList<>();
|
||||
queue.add(root);
|
||||
// 初始化一个列表,用于保存遍历序列
|
||||
List<Integer> list = new ArrayList<>();
|
||||
while (!queue.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user