var pathSum = function(root, targetSum) {
let arr=[]
if(root===null){
return arr
}
//把根节点的值放到路径中
let path=[root.val]
//递归函数
const dd=function(root,count,path){
//如果为叶子节点,且和为count
if(root.left==null&&root.right==null&&count==0){
arr.push([...path])
return
}
if(root.left==null&&root.right==null){
return
}
if(root.left){
path.push(root.left.val)
count-=root.left.val
dd(root.left,count,path)
//回溯
path.pop(root.left.val)
count+=root.left.val
}
if(root.right){
path.push(root.right.val)
count-=root.right.val
dd(root.right,count,path)
//回溯
path.pop(root.right.val)
count+=root.right.val
}
return
}
dd(root,targetSum-root.val,path)
return arr
};