leetcode-104-二叉树深度

// https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/
var maxDepth = function(root) {
if (!root) return 0;

const leftDepth = maxDepth(root.left);
const rightDepth = maxDepth(root.right);

return leftDepth > rightDepth ? leftDepth + 1 : rightDepth + 1;
};

你可能感兴趣的:(leetcode-104-二叉树深度)