Python Solution O(n)


#1

class Solution:
# @param A : root node of tree
# @return a list of integers
def solve(self, A):
if A == None:
return None
q = []
res = []
q.append(A)
while(len(q) != 0):
node = q.pop(0)
res.append(node.val)
if node.right:
q.append(node.right)
if node.left:
q.append(node.left)
res = res[::-1]
return res