Created
October 28, 2018 14:26
-
-
Save arpi-r/1b1495450efef2fc41817ad06b3512ad to your computer and use it in GitHub Desktop.
codebuddy week7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for a binary tree node | |
# class TreeNode: | |
# def __init__(self, x): | |
# self.val = x | |
# self.left = None | |
# self.right = None | |
class Solution: | |
# @param A : root node of tree | |
# @return a list of list of integers | |
def levelOrder(self, A): | |
r=[] | |
r1=[] | |
t=[] | |
if A==None: | |
return r | |
t.append(A.val) | |
r.append(t) | |
temp=[] | |
temp.append(A) | |
r1.append(temp) | |
i=0 | |
while i<len(r): | |
l=r1[i] | |
t1=[] | |
t2=[] | |
j=0 | |
while j<len(l): | |
if l[j].left!=None: | |
t1.append(l[j].left) | |
t2.append(l[j].left.val) | |
if l[j].right!=None: | |
t1.append(l[j].right) | |
t2.append(l[j].right.val) | |
j=j+1 | |
if(len(t1)!=0): | |
r1.append(t1) | |
r.append(t2) | |
i=i+1 | |
return r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment