标签:
/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution { public: vector<vector<int>>res; void findpath(TreeNode* root,int val,int sum,vector<int>& path) { if(root==NULL) return ; sum+=root->val; path.push_back(root->val); bool isleaf=false; if(root->left==NULL&&root->right==NULL) isleaf=true; if(sum==val&&isleaf) res.push_back(path); if(root->left) findpath(root->left,val,sum,path); if(root->right) findpath(root->right,val,sum,path); path.pop_back(); } vector<vector<int> > FindPath(TreeNode* root,int expectNumber) { if(root==NULL) return res; vector<int> path; int sum=0; findpath(root,expectNumber,sum,path); return res; } };
标签:
原文地址:http://www.cnblogs.com/daocaorenblog/p/5357110.html