Python compiler giving TLE


#1

The python compiler is giving TLE, even when I am running the editorial solution. Please check.


#2

No, its not. i submitted my code and it worked fine.
class Solution:
# @param A : root node of tree
# @return a list of integers
def traverse(self,A,ind,l):
if(A!=None):
if(ind>len(l)-1):
l.append([])
l[ind].append(A.val)
self.traverse(A.left,ind+1,l)
self.traverse(A.right,ind,l)
else:
return

def solve(self, A):
    l=[]
    self.traverse(A,0,l)
    ans=[]
    for i in l:
        ans+=i
    return ans

#3

This is my solution, it got accepted for Python 2.7 but Python 3.5 gives TLE.

def solve(self, A):
ans = []

    def store_data(root, curr):
        if not root:
            return
        
        try:
            ans[curr].append(root.val)
        except:
            ans.append([root.val])
        
        store_data(root.left, curr + 1)
        store_data(root.right, curr)
            
    
    store_data(A, 0)
    join = []
    for i in range(len(ans)):
        join += ans[i]
    
    return join