Why run code result different from submit result?


  • 0
    S

    When input is [1,2] , I got right result from run code. But got [1,1,2] from submit button.

    class Solution(object):
        
        targetDepth = 0
        curtD = 0
        res = []
        def helper(self, root):
            
            if root is None:
                return
            
            if self.targetDepth == self.curtD:
                self.res.append(root.val)
                self.targetDepth += 1
                
            self.curtD += 1
            self.helper(root.right)
    
            self.helper(root.left)
            self.curtD -= 1
            
            return 
            
            
        
        def rightSideView(self, root):
            """
            :type root: TreeNode
            :rtype: List[int]
            """
            
            self.helper(root)
            return self.res
    

Log in to reply
 

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