/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number}
*/
var maxDepth = function(root) {
if(!root) return 0;
const queue = [[root, 1]];
while(queue.length){
var [obj, max] = queue.shift()
if(obj.left) {queue.push([obj.left, max+1]); }
if(obj.right) {queue.push([obj.right, max+1]);}
}
return max
};
力扣104 二叉树最大深度
最新推荐文章于 2024-06-14 05:45:37 发布