Python Solution


  • 0
    M

    '''
    class Solution(object):
    def pathSum(self, root, sum):

        if root == None:
            return 0
        
        res = self.findPaths(root, sum)
        res += self.pathSum(root.left, sum)
        res += self.pathSum(root.right, sum)
        
        return res
    
    def findPaths(self, root, sum):
        
        if root == None:
            return 0
        
        res = 0
        
        if root.val == sum:
            res += 1
            
        res += self.findPaths(root.left, sum-root.val)
        res += self.findPaths(root.right, sum-root.val)
        
        return res
    

    '''


Log in to reply
 

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