@yuez1989 yeah! but we add two only when the node has both left and right child, in case of only one child we add one only.

def diameterOfBinaryTree(self, root): """ :type root: TreeNode :rtype: int """ self.dim = 0 def lpath(node): if node is None: return 0 if node.left is None and node.right is None: return 0 l = lpath(node.left) r = lpath(node.right) if node.left is not None and node.right is not None: self.dim = max(self.dim,l+r+2) else: self.dim = max(self.dim,l+r+1) return max(l,r)+1; lpath(root) return self.dimLeetCode Weekly Contest 24