File tree Expand file tree Collapse file tree 1 file changed +29
-3
lines changed Expand file tree Collapse file tree 1 file changed +29
-3
lines changed Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
22import math
3+ from typing import List
4+
5+
36class TreeNode :
47 def __init__ (self , x ):
58 self .val = x
@@ -8,6 +11,29 @@ def __init__(self, x):
811
912
1013class Solution_101_110 (object ):
14+ def levelOrder (self , root : TreeNode ) -> List [List [int ]]:
15+ """
16+ 102
17+ :param root:
18+ :return:
19+ """
20+ results = []
21+
22+ def recursive_tree (level , node ):
23+ if not node :
24+ return
25+ if len (results ) == level :
26+ level_list = [node .val ]
27+ results .append (level_list )
28+ else :
29+ results [level ].append (node .val )
30+
31+ recursive_tree (level + 1 , node .left )
32+ recursive_tree (level + 1 , node .right )
33+
34+ recursive_tree (0 , root )
35+ return results
36+
1137 def maxDepth (self , root ):
1238 """
1339 104
@@ -17,7 +43,7 @@ def maxDepth(self, root):
1743 if not root :
1844 return 0
1945
20- left_depth = self .maxDepth (root .left )+ 1
21- right_depth = self .maxDepth (root .right )+ 1
46+ left_depth = self .maxDepth (root .left ) + 1
47+ right_depth = self .maxDepth (root .right ) + 1
2248
23- return left_depth if left_depth > right_depth else right_depth
49+ return left_depth if left_depth > right_depth else right_depth
You can’t perform that action at this time.
0 commit comments