```
var pathSum = function(root, sum) {
var result = [];
var explore = function(root, sum, arr) {
if(root === null)
return;
sum -= root.val;
arr.push(root.val);
if(sum === 0 && root.left === null && root.right === null){
result.push(arr);
}else{
explore(root.left, sum, arr.slice());
explore(root.right, sum, arr.slice());
}
};
explore(root, sum, new Array());
return result;
};
```