Skip to content

Commit dde2038

Browse files
committed
fix: display lc problem: No.0112 c++ solution
No.0112.Path Sum
1 parent 8255bae commit dde2038

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

solution/0100-0199/0112.Path Sum/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ class Solution {
101101
}
102102
```
103103

104+
### **C++**
105+
106+
```cpp
107+
class Solution {
108+
public:
109+
bool hasPathSum(TreeNode* root, int sum) {
110+
111+
if(root == NULL)return false;
112+
if(root->right == NULL && root->left == NULL && sum == root->val)return true;
113+
114+
bool leftTrue = hasPathSum(root->left,sum - root->val);
115+
bool rightTrue = hasPathSum(root->right,sum - root->val);
116+
117+
return (leftTrue || rightTrue);
118+
}
119+
};
120+
```
121+
104122
### **...**
105123
106124
```

solution/0100-0199/0112.Path Sum/README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ class Solution {
8989
}
9090
```
9191

92+
### **C++**
93+
94+
```cpp
95+
class Solution {
96+
public:
97+
bool hasPathSum(TreeNode* root, int sum) {
98+
99+
if(root == NULL)return false;
100+
if(root->right == NULL && root->left == NULL && sum == root->val)return true;
101+
102+
bool leftTrue = hasPathSum(root->left,sum - root->val);
103+
bool rightTrue = hasPathSum(root->right,sum - root->val);
104+
105+
return (leftTrue || rightTrue);
106+
}
107+
};
108+
```
109+
92110
### **...**
93111
94112
```

0 commit comments

Comments
 (0)