题解 | #二叉树的最大深度#
二叉树的最大深度
http://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73
采用层序遍历
if(!root) return 0
let res = []
let queue = []
queue.push(root)
let num = 0
while(queue.length){
let len = queue.length
num++
for(let i = 0; i < len; i++){
let node = queue.shift()
if(node.left) queue.push(node.left)
if(node.right) queue.push(node.right)
}
}
return num
}