Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c45c52f

Browse files
python: add problem 111 and unittest
1 parent a9793e0 commit c45c52f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Python/sln_101_200/solution_111_120.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
# -*- coding: utf-8 -*-
22
from typing import List
3+
from common_utils import *
34

45

56
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+
626
def generate(self, numRows: int) -> List[List[int]]:
727
"""
828
118

0 commit comments

Comments
 (0)