Created
March 13, 2019 22:03
-
-
Save tech-cow/c54ffc6b650171d4c62f5d43f1bf8e2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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