-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinOrder.py
32 lines (25 loc) · 845 Bytes
/
inOrder.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
# Leetcode: https://leetcode.com/submissions/detail/115175620/
# Inorder traverse, not very difficult although I'm not too sure how to do iteratively right now.
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def inorderTraversal(self, root):
"""
:type root: TreeNode
:rtype: List[int]
"""
nodes = []
if (root is None):
return []
self.traverse(root, nodes)
return nodes
def traverse(self, root, nodes):
if (root.left):
self.traverse(root.left, nodes)
nodes.append(root.val)
if (root.right):
self.traverse(root.right, nodes)