###########################################################################
#                                                                         #
# Author: Daniel Mock                                                     #
#                                                                         #
# Purpose: To document progress in learning algorithms & data structures  #
#                                                                         #
# References: This question was generated by leetcode.com. The solution   #
# to the question was generated by Daniel Mock.                           #
#                                                                         #
###########################################################################


# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

#Come back to this one, uses shallow copy

class Solution:
    def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]:
        if root is None: return
        loc_list = []
        global_list = []
        val = 0

        return self.recurse(root, sum, val, loc_list, global_list)

    def recurse(self, root, sum, val, loc_list, global_list):
        if root:
            val+= root.val
            loc_list.append(root.val)

            self.recurse(root.left,sum,val,loc_list.copy(), global_list)
            self.recurse(root.right,sum,val,loc_list.copy(), global_list)

            if val == sum and root.left is None and root.right is None:
                global_list.append(loc_list)
            return global_list
