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:
ZongYangL
2023-07-19 01:37:55 +08:00
committed by GitHub
parent 7a6fd4b3dd
commit 03cbf5b972
3 changed files with 9 additions and 5 deletions

View File

@ -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()) {