From 7c37da4bec63da24a539900d3cbded9b983e5252 Mon Sep 17 00:00:00 2001 From: Azureki Date: Fri, 7 Dec 2018 20:59:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=A0=91=E7=9A=84=E6=B7=B1?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lc104. Maximum Depth of Binary Tree.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lc104. Maximum Depth of Binary Tree.py diff --git a/lc104. Maximum Depth of Binary Tree.py b/lc104. Maximum Depth of Binary Tree.py new file mode 100644 index 0000000..fc40816 --- /dev/null +++ b/lc104. Maximum Depth of Binary Tree.py @@ -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))