Created
April 12, 2020 06:19
-
-
Save vamsitallapudi/6213c6eb886f1786847a0b683a90721b 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: | |
def diameterOfBinaryTree(self, root: TreeNode) -> int: | |
self.globalLongestPath = 0 | |
self.depth(root) | |
return self.globalLongestPath | |
def depth(self, node:TreeNode)-> int: | |
if not node: | |
return 0 | |
left = self.depth(node.left) | |
right = self.depth(node.right) | |
self.globalLongestPath = max(self.globalLongestPath, left + right) | |
return max(left,right)+1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment