Skip to content

Commit

Permalink
二叉树的深度
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Dec 7, 2018
1 parent 48c1627 commit 7c37da4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lc104. Maximum Depth of Binary Tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None


class Solution:
def maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if not root:
return 0
else:
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))

0 comments on commit 7c37da4

Please sign in to comment.