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 fc196f8 commit af3aae9Copy full SHA for af3aae9
solutions/binary-tree-level-order-traversal.py
@@ -0,0 +1,27 @@
1
+"""
2
+102. Binary Tree Level Order Traversal
3
+- https://leetcode.com/problems/binary-tree-level-order-traversal/
4
5
+
6
+# Method 1
7
+# Using List
8
+class Solution(object):
9
+ def levelOrder(self, root):
10
+ """
11
+ :type root: TreeNode
12
+ :rtype: List[List[int]]
13
14
+ result = []
15
+ if not root:
16
+ return result
17
+ temp = [root]
18
+ while temp:
19
+ ans = []
20
+ temp2 = []
21
+ for i in range(len(temp)):
22
+ ans.append(temp[i].val)
23
+ if temp[i].left: temp2.append(temp[i].left)
24
+ if temp[i].right: temp2.append(temp[i].right)
25
+ result.append(ans)
26
+ temp = temp2
27
0 commit comments