Skip to content

Instantly share code, notes, and snippets.

@tech-cow
Created March 13, 2019 22:03
Show Gist options
  • Select an option

  • Save tech-cow/c54ffc6b650171d4c62f5d43f1bf8e2c to your computer and use it in GitHub Desktop.

Select an option

Save tech-cow/c54ffc6b650171d4c62f5d43f1bf8e2c to your computer and use it in GitHub Desktop.
class Solution(object):
def diameterOfBinaryTree(self, root):
if not root: return 0
left = self.getHeight(root.left)
right= self.getHeight(root.right)
return max(left + right, max(self.diameterOfBinaryTree(root.left), self.diameterOfBinaryTree(root.right)))
def getHeight(self, root):
if not root: return 0
left = self.getHeight(root.left)
right = self.getHeight(root.right)
return max(left, right) + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment