Python 66ms


  • 0
    M

    '''

    class Solution(object):

    def pathSum(self, root, sum):
        if not root:
            return []
            
        self.result = []
        self.findPathSum(root, sum, [])
        
        return self.result
        
    
    def findPathSum(self, root, sum, path):
        
        path.append(root.val)
        if not root.left and not root.right and root.val == sum:
            self.result.append(list(path))
        
        if root.left: self.findPathSum(root.left, sum-root.val, path)
        if root.right: self.findPathSum(root.right, sum-root.val, path)
        path.pop()
    

    '''


Log in to reply
 

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