Find the length of the diameter of a binary tree.
O(n)
def diameterOfBinaryTree(root): res = 0 def dfs(node): nonlocal res if not node: return 0 left = dfs(node.left) right = dfs(node.right) res = max(res, left + right) return 1 + max(left, right) dfs(root) return res