-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path94.py
43 lines (38 loc) · 1.19 KB
/
94.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class TreeNode(object):
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
class Solution(object):
def inorderTraversal(self, root):
if root is not None:
if root.left==None and root.right==None:
return [root.val]
flag1=flag2=0
if root.left!=None:
r1=self.inorderTraversal(root.left)
flag1=1
if root.right!=None:
r2=self.inorderTraversal(root.right)
flag2=1
mylist=[]
if flag1:
for x in r1:
mylist.append(x)
mylist.append(root.val)
if flag2:
for x in r2:
mylist.append(x)
return mylist
"""
#root=TreeNode(1,None,TreeNode(2,TreeNode(3),TreeNode(4)))
root = TreeNode(1)
root.left = TreeNode(2)
root.right = TreeNode(3)
root.left.left = TreeNode(4)
root.left.right = TreeNode(5)
root.right.left = TreeNode(6)
root.right.right = TreeNode(7)
solution_instance=Solution()
print(solution_instance.inorderTraversal(root))
"""