1 Star 0 Fork 0

Neo_1001/LeetCode刷题记录

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
LC_111.java 648 Bytes
Copy Edit Raw Blame History
Neo_1001 authored 2024-04-10 22:16 . first commit
package LeetCode;
import java.util.*;
public class LC_111 {
public int minDepth(TreeNode root) {
if (root == null) return 0;
Queue<TreeNode> que = new LinkedList<>();
que.add(root);
int level = 0;
while (!que.isEmpty()) {
int len = que.size();
level++;
while (len > 0) {
TreeNode p = que.poll();
if (p.left != null) que.add(p.left);
if (p.right != null) que.add(p.right);
if (p.right == null && p.left == null) return level;
len--;
}
}
return level;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/neo1001/leet-code-practice-record.git
git@gitee.com:neo1001/leet-code-practice-record.git
neo1001
leet-code-practice-record
LeetCode刷题记录
master

Search