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 41df0fa commit b18a342Copy full SHA for b18a342
Binary_Tree_Inorder_Traversal.py
@@ -0,0 +1,40 @@
1
+# Given a binary tree, return the inorder traversal of its nodes' values.
2
+#
3
+# Example:
4
5
+# Input: [1,null,2,3]
6
+# 1
7
+# \
8
+# 2
9
+# /
10
+# 3
11
12
+# Output: [1,3,2]
13
+# Definition for a binary tree node.
14
+
15
16
+class TreeNode:
17
+ def __init__(self, x):
18
+ self.val = x
19
+ self.left = None
20
+ self.right = None
21
22
23
+class Solution:
24
+ def inorderTraversal(self, root):
25
26
+ stack = []
27
+ res = []
28
29
+ while stack or root:
30
+ while root:
31
+ stack.append(root)
32
+ root = root.left
33
34
+ root = stack.pop()
35
36
+ res.append(root.val)
37
38
+ root = root.right
39
40
+ return res
0 commit comments