111.二叉树的最小深度
来源:8-6 LeetCode:111. 二叉树的最小深度

iFun6824488
2021-08-09
var minDepth = function(root) {
if(!root) return 0;
const q = [[root, 1]];
while(q.length) {
const [n, i] = q.shift();
if(!n.left && !n.right) return i;
if(n.left) q.push([n.left, i+1]);
if(n.right) q.push([n.right, i+1]);
}
};
minDepth([2,null,3,null,4,null,5,null,6]);
dubug的时候,每次到return就结束了,只有一轮循环,而放在leetcode上确能正常运行
写回答
1回答
-
lewis
2021-08-10
如果自己debug,需要构造一个二叉树,而不是用数组。
00
相似问题