File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
solution/0100-0199/0112.Path Sum Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,24 @@ class Solution {
101
101
}
102
102
```
103
103
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
+
104
122
### **...**
105
123
106
124
```
Original file line number Diff line number Diff line change @@ -89,6 +89,24 @@ class Solution {
89
89
}
90
90
```
91
91
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
+
92
110
### **...**
93
111
94
112
```
You can’t perform that action at this time.
0 commit comments