Skip to content

Commit

Permalink
Binary Tree Preorder Traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliehan23 committed Feb 20, 2014
1 parent a174198 commit 99e75c8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions preorderTraversal.py
@@ -0,0 +1,26 @@
# Definition for a binary tree node
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None

class Solution:
# @param root, a tree node
# @return a list of integers
def preorderTraversal(self, root):
ll =[]
self.preOrder(root, ll)
return ll

def preOrder(self, root, ll):
if not root:
return ll
ll.append(root.val)
self.preOrder(root.left,ll)
self.preOrder(root.right,ll)
return ll




0 comments on commit 99e75c8

Please sign in to comment.