From f16f386c355c2865ce2d833142db56538c7be3ad Mon Sep 17 00:00:00 2001 From: linlihong <747682928@qq.com> Date: Fri, 30 Aug 2024 16:15:40 +0800 Subject: [PATCH] =?UTF-8?q?2024/8/30=20Hot100=20binaryTree=20=E6=98=A8?= =?UTF-8?q?=E6=97=A5=E7=9A=84=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cool/hot100/binary_tree/Num102.java | 28 +++++++++++++++++-- .../LeetCode20240829.java | 6 ++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/cool/hot100/binary_tree/Num102.java b/src/main/java/com/cool/hot100/binary_tree/Num102.java index b1d4ae8..4ffe021 100644 --- a/src/main/java/com/cool/hot100/binary_tree/Num102.java +++ b/src/main/java/com/cool/hot100/binary_tree/Num102.java @@ -1,21 +1,45 @@ package com.cool.hot100.binary_tree; -import java.util.List; +import java.util.*; /** * Created with IntelliJ IDEA. * * @Author: Cool - * @Date: 2024/08/28/17:24 + * @Date: 2024/08/29/17:24 * DayNumber 4 * Hard 2 * Level ? + * @Description 昨日题今日做 + * FinishTime: 2024/8/30/ */ public class Num102 { public List> levelOrder(TreeNode root) { + List> retList = new ArrayList<>(); + if (root == null) { + return retList; + } + Queue queue = new LinkedList<>(); + queue.add(root); + while (!queue.isEmpty()) { + List list=new ArrayList<>(); + int size = queue.size(); + for (int i = 0; i < size; i++) { + TreeNode head = queue.poll(); + list.add(head.val); + if (head.left != null) { + queue.add(head.left); + } + if (head.right != null) { + queue.add(head.right); + } + } + retList.add(list); + } + return retList; } } diff --git a/src/main/java/com/cool/one_question_per_day/LeetCode20240829.java b/src/main/java/com/cool/one_question_per_day/LeetCode20240829.java index db565b4..88ca60f 100644 --- a/src/main/java/com/cool/one_question_per_day/LeetCode20240829.java +++ b/src/main/java/com/cool/one_question_per_day/LeetCode20240829.java @@ -9,7 +9,7 @@ package com.cool.one_question_per_day; * Hard 1 */ public class LeetCode20240829 { - public boolean satisfiesConditions(int[][] grid) { - - } +// public boolean satisfiesConditions(int[][] grid) { +// +// } }