/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param root TreeNode类 
     * @param sum int整型 
     * @return int整型vector<vector<>>
     */
    vector<vector<int>> ret;
    void dfs(TreeNode* root, int target, vector<int>& path) {
        /* 如果是叶子节点,而且 val = target,push后return
         如果val != target,return null
         如果不是叶子节点,dfs,left-val, right - val
        */
        if(!root) {
            return;
        }
        path.push_back(root->val);
        target -= root->val;
        if (!root->left && !root->right && target == 0) {
            ret.push_back(path);
        } else {
            dfs(root->left, target, path);
            dfs(root->right, target, path);
        }
        path.pop_back();
    }
    vector<vector<int> > pathSum(TreeNode* root, int sum) {
        if(!root && sum != 0) {
            return ret;
        }
        vector<int>vec;
        dfs(root, sum, vec);
        return ret;
    }
};