mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0112.路径总和.md
This commit is contained in:
@ -250,7 +250,7 @@ private:
|
|||||||
vector<vector<int>> result;
|
vector<vector<int>> result;
|
||||||
vector<int> path;
|
vector<int> path;
|
||||||
// 递归函数不需要返回值,因为我们要遍历整个树
|
// 递归函数不需要返回值,因为我们要遍历整个树
|
||||||
void traversal(treenode* cur, int count) {
|
void traversal(TreeNode* cur, int count) {
|
||||||
if (!cur->left && !cur->right && count == 0) { // 遇到了叶子节点且找到了和为sum的路径
|
if (!cur->left && !cur->right && count == 0) { // 遇到了叶子节点且找到了和为sum的路径
|
||||||
result.push_back(path);
|
result.push_back(path);
|
||||||
return;
|
return;
|
||||||
@ -276,10 +276,10 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
vector<vector<int>> pathsum(treenode* root, int sum) {
|
vector<vector<int>> pathSum(TreeNode* root, int sum) {
|
||||||
result.clear();
|
result.clear();
|
||||||
path.clear();
|
path.clear();
|
||||||
if (root == null) return result;
|
if (root == NULL) return result;
|
||||||
path.push_back(root->val); // 把根节点放进路径
|
path.push_back(root->val); // 把根节点放进路径
|
||||||
traversal(root, sum - root->val);
|
traversal(root, sum - root->val);
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user