mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 0112.路径总和.md
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user