Update 0112.路径总和.md

This commit is contained in:
ayao98
2023-04-03 15:48:51 +08:00
committed by GitHub
parent f7988e06dc
commit 34e1b0ab5c

View File

@ -250,7 +250,7 @@ private:
vector<vector<int>> result;
vector<int> path;
// 递归函数不需要返回值,因为我们要遍历整个树
void traversal(treenode* cur, int count) {
void traversal(TreeNode* cur, int count) {
if (!cur->left && !cur->right && count == 0) { // 遇到了叶子节点且找到了和为sum的路径
result.push_back(path);
return;
@ -276,10 +276,10 @@ private:
}
public:
vector<vector<int>> pathsum(treenode* root, int sum) {
vector<vector<int>> pathSum(TreeNode* root, int sum) {
result.clear();
path.clear();
if (root == null) return result;
if (root == NULL) return result;
path.push_back(root->val); // 把根节点放进路径
traversal(root, sum - root->val);
return result;