Different Results between my Local IDE Run and OJ


  • 0
    S

    Can anyone help me figure out why my code does not generate [[1]] at OJ?
    My code generates the correct result on my local IDE.

    Thanks in advance.
    Input: {1}
    Output: 1
    Expected: [[1]]

        def levelOrderBottom(self, root):
          res = []
          if root == None:
            return res
          else:
            level = []
            q = collections.deque([])
            q.append(root)
            curChild=1  
            nexChild=0
            
            while q:
              n = q.popleft()
              curChild-=1
        
              print n.val
              level.append(n.val)
              
              if n.left!=None:
                q.append(n.left)
                nexChild+=1
                
              if n.right!=None:
                q.append(n.right)
                nexChild+=1
                
              if curChild==0:
                curChild = nexChild
                nexChild = 0
                res.append(list(level))        
                del level[:]
                
            res.reverse()
            return res

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.