Update 0112.路径总和.md

原有的代码leetcode上无法通过编译
This commit is contained in:
El nino
2023-01-14 15:06:56 +08:00
committed by GitHub
parent 7d822fe65a
commit c201b947a5

View File

@ -155,14 +155,14 @@ public:
以上代码精简之后如下:
```cpp
class solution {
class Solution {
public:
bool hasPathSum(TreeNode* root, int sum) {
if (root == null) return false;
if (!root) return false;
if (!root->left && !root->right && sum == root->val) {
return true;
}
return haspathsum(root->left, sum - root->val) || haspathsum(root->right, sum - root->val);
return hasPathSum(root->left, sum - root->val) || hasPathSum(root->right, sum - root->val);
}
};
```