#543. Diameter of Binary Tree
var diameterOfBinaryTree = function(root) {
let res = 0
function DFS(node) {
if (! node) return 0
let left = DFS(node.left)
let right = DFS(node.right)
res = Math.max(res, left + right)
return 1 + Math.max(left, right)
}
DFS(root)
return res
};
ย