We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a9793e0 commit c45c52fCopy full SHA for c45c52f
Python/sln_101_200/solution_111_120.py
@@ -1,8 +1,28 @@
1
# -*- coding: utf-8 -*-
2
from typing import List
3
+from common_utils import *
4
5
6
class Solution_111_120(object):
7
+ def minDepth(self, root: TreeNode) -> int:
8
+ """
9
+ 111
10
+ :param root:
11
+ :return:
12
13
+ if not root:
14
+ return 0
15
+ if root.left and root.right:
16
+ left_depth = self.minDepth(root.left)
17
+ right_depth = self.minDepth(root.right)
18
+ return min(left_depth, right_depth) + 1
19
+ elif not root.left and not root.right:
20
+ return 1
21
+ elif not root.right:
22
+ return self.minDepth(root.left) + 1
23
+ else:
24
+ return self.minDepth(root.right) + 1
25
+
26
def generate(self, numRows: int) -> List[List[int]]:
27
"""
28
118
0 commit comments