problemscpp
A collection of my answers to algorithm problems in c++.
函数
acwing::acwing3766 命名空间参考

函数

int pathSum (TreeNode *root)
 
int pathSum (TreeNode *root, int level)
 

函数说明

◆ pathSum() [1/2]

int acwing::acwing3766::pathSum ( TreeNode root)

在文件 acwing408.cpp307 行定义.

307 {
308 return pathSum(root, 0);
309 }
int pathSum(TreeNode *root, int level)
Definition: acwing408.cpp:311

引用了 pathSum() , 以及 acwing::acwing3786::root.

◆ pathSum() [2/2]

int acwing::acwing3766::pathSum ( TreeNode root,
int  level 
)

在文件 acwing408.cpp311 行定义.

311 {
312 if(root == nullptr) {
313 return 0;
314 }
315 if(root->left == nullptr && root->right == nullptr) {
316 return level * root->val;
317 }
318 int leftVal = pathSum(root->left, level + 1);
319 int rightVal = pathSum(root->right, level + 1);
320 return leftVal + rightVal;
321 }
TreeNode * right
Definition: acwing408.h:24
TreeNode * left
Definition: acwing408.h:23

引用了 acwing::TreeNode::left, pathSum(), acwing::TreeNode::right, acwing::acwing3786::root , 以及 acwing::TreeNode::val.

被这些函数引用 pathSum().