```
class Solution(object):
def diameterOfBinaryTree(self, root):
self.max_len = 0
def helper(root):
if not root: return 0
l, r = helper(root.left), helper(root.right)
self.max_len = max(self.max_len, l + r)
return max(l, r) + 1
helper(root)
return self.max_len
```