`class Solution(object):

```
def pathSum(self, root, sum):
return self.pathSum2(root, sum, [])
def pathSum2(self, root, sum, soFar):
if not root:
return []
remain = sum - root.val
if root.right is None and root.left is None:
if remain == 0:
soFar.append(root.val)
return [soFar]
else:
return []
soFar.append(root.val)
return self.pathSum2(root.left, remain, soFar[:]) + self.pathSum2(root.right, remain, soFar[:])`
```