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