2024/8/30 Hot100 binaryTree 昨日的题
This commit is contained in:
parent
29c55c38a9
commit
f16f386c35
|
@ -1,21 +1,45 @@
|
||||||
package com.cool.hot100.binary_tree;
|
package com.cool.hot100.binary_tree;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
*
|
*
|
||||||
* @Author: Cool
|
* @Author: Cool
|
||||||
* @Date: 2024/08/28/17:24
|
* @Date: 2024/08/29/17:24
|
||||||
* DayNumber 4
|
* DayNumber 4
|
||||||
* Hard 2
|
* Hard 2
|
||||||
* Level ?
|
* Level ?
|
||||||
|
* @Description 昨日题今日做
|
||||||
|
* FinishTime: 2024/8/30/
|
||||||
*/
|
*/
|
||||||
public class Num102 {
|
public class Num102 {
|
||||||
|
|
||||||
|
|
||||||
public List<List<Integer>> levelOrder(TreeNode root) {
|
public List<List<Integer>> levelOrder(TreeNode root) {
|
||||||
|
List<List<Integer>> retList = new ArrayList<>();
|
||||||
|
if (root == null) {
|
||||||
|
return retList;
|
||||||
|
}
|
||||||
|
Queue<TreeNode> queue = new LinkedList<>();
|
||||||
|
queue.add(root);
|
||||||
|
while (!queue.isEmpty()) {
|
||||||
|
List<Integer> 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ package com.cool.one_question_per_day;
|
||||||
* Hard 1
|
* Hard 1
|
||||||
*/
|
*/
|
||||||
public class LeetCode20240829 {
|
public class LeetCode20240829 {
|
||||||
public boolean satisfiesConditions(int[][] grid) {
|
// public boolean satisfiesConditions(int[][] grid) {
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue