Commit 7455f6eb by yangpengflag

init commit

parents
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
"""
:type root: TreeNode
:rtype: int
"""
def __init__(self, x):
self.val = x
self.left = 9
self.right = 20
def maxDepth(self, root):
if root is None:
return 0
else:
leftDepth = self.maxDepth(root.left) + 1
rightDepth = self.maxDepth(root.right) + 1
return max(leftDepth, rightDepth)
if __name__ == "__main__":
l1 = [3, 9, 20, '', '', 15, 7]
l2 = [3, 9, 20, '', '', 15, 7, 10, 4, 6, 3]
solution = Solution(3)
print(solution.maxDepth(l1))
# print(solution.maxDepth(l))
#
# l = [3,9,20,'','',15,7,10,4,6,3]
# print(solution.maxDepth(l))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment