Compare commits
No commits in common. "746e23928b77726d92707dc4bba1961edc2d21d6" and "1eaa8169f36d5d60ccf866b02f78895bb7da59bc" have entirely different histories.
746e23928b
...
1eaa8169f3
|
@ -1,45 +1,21 @@
|
||||||
package com.cool.hot100.binary_tree;
|
package com.cool.hot100.binary_tree;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
*
|
*
|
||||||
* @Author: Cool
|
* @Author: Cool
|
||||||
* @Date: 2024/08/29/17:24
|
* @Date: 2024/08/28/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