图片说明
/*
 * function TreeNode(x) {
 *   this.val = x;
 *   this.left = null;
 *   this.right = null;
 * }
 */

/**
  * 
  * @param root TreeNode类 
  * @param sum int整型 
  * @return int整型二维数组
  */
function pathSum( root ,  sum ) {
    // write code here
    if(!root) return []//false
    var result = []
    function dfs(root,cursum,path){
        if(!root) return
        if(root){
            cursum += root.val
            path.push(root.val)
            if(cursum==sum&&!root.left&&!root.right){
                result.push(path)
                return
            }
            if(root.left) dfs(root.left,cursum,[...path])
            if(root.right) dfs(root.right,cursum,[...path])
        }
    }
    dfs(root,0,[])
    return result;
    //判断是否存在
    //return result.length==0? false:true;
}
module.exports = {
    pathSum : pathSum
};