mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 07:35:35 +08:00
Update 0112.路径总和.md
原有的代码leetcode上无法通过编译
This commit is contained in:
@ -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);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
Reference in New Issue
Block a user