leetcode-104-二叉树深度
2021-03-29 本文已影响0人
kayleeWei
// 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;
};