parent
7d822fe65a
commit
c201b947a5
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
|
|
|||
Loading…
Reference in New Issue