var diameterOfBinaryTree = function (root) { let Max = 0; const depth = (root) => { if (!root) return 0; let l = depth(root.left); let r = depth(root.right); if (l + r > Max) { Max = l + r; } return Math.max(l, r) + 1; }; depth(root); return Max; };
2024-01-05 13:40:10
var diameterOfBinaryTree = function (root) { let Max = 0; const depth = (root) => { if (!root) return 0; let l = depth(root.left); let r = depth(root.right); if (l + r > Max) { Max = l + r; } return Math.max(l, r) + 1; }; depth(root); return Max; };