File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ import math
3
+ class TreeNode :
4
+ def __init__ (self , x ):
5
+ self .val = x
6
+ self .left = None
7
+ self .right = None
8
+
9
+
10
+ class Solution_101_110 (object ):
11
+ def maxDepth (self , root ):
12
+ """
13
+ 104
14
+ :return:
15
+ """
16
+
17
+ if not root :
18
+ return 0
19
+
20
+ left_depth = self .maxDepth (root .left )+ 1
21
+ right_depth = self .maxDepth (root .right )+ 1
22
+
23
+ return left_depth if left_depth > right_depth else right_depth
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ from unittest import TestCase
3
+ from sln_101_200 .solution_101_110 import Solution_101_110 , TreeNode
4
+
5
+
6
+ class TestSolution_101_110 (TestCase ):
7
+ def setUp (self ):
8
+ self .sln = Solution_101_110 ()
9
+
10
+ def test_maxDepth (self ):
11
+ left_1 = TreeNode (10 )
12
+ left_1_1 = TreeNode (111 )
13
+ left_1_1_1 = TreeNode (1111 )
14
+ left_1_1 .left = left_1_1_1
15
+ right_1_2 = TreeNode (112 )
16
+ left_1 .left = left_1_1
17
+ right_1 = TreeNode (20 )
18
+ right_1 .right = right_1_2
19
+ root = TreeNode (121 )
20
+ root .left = left_1
21
+ root .right = right_1
22
+ depth = self .sln .maxDepth (root )
23
+ self .assertEqual (depth , 4 )
You can’t perform that action at this time.
0 commit comments