fork download
  1. class Solution {
  2. public:
  3. int countPathHelper(TreeNode* node, int sum, int currentSum){
  4. if(node == NULL) return 0;
  5. currentSum += node->val;
  6. if(currentSum == sum)
  7. return countPathHelper(node->left,sum,currentSum) + countPathHelper(node->right,sum,currentSum) + (currentSum == sum);
  8. }
  9.  
  10. int pathSum(TreeNode* root, int sum) {
  11. if(root == NULL) return 0;
  12. return countPathHelper(root,sum,0) + pathSum(root->right,sum) + pathSum(root->left,sum);
  13. }
  14. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:25: error: ‘TreeNode’ has not been declared
     int countPathHelper(TreeNode* node, int sum, int currentSum){
                         ^~~~~~~~
prog.cpp:10:17: error: ‘TreeNode’ has not been declared
     int pathSum(TreeNode* root, int sum) {
                 ^~~~~~~~
prog.cpp: In member function ‘int Solution::countPathHelper(int*, int, int)’:
prog.cpp:4:20: error: ‘NULL’ was not declared in this scope
         if(node == NULL) return 0;
                    ^~~~
prog.cpp:4:20: note: ‘NULL’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
prog.cpp:1:1:
+#include <cstddef>
 class Solution {
prog.cpp:4:20:
         if(node == NULL) return 0;
                    ^~~~
prog.cpp:5:29: error: request for member ‘val’ in ‘* node’, which is of non-class type ‘int’
         currentSum += node->val;
                             ^~~
prog.cpp:7:42: error: request for member ‘left’ in ‘* node’, which is of non-class type ‘int’
             return countPathHelper(node->left,sum,currentSum) + countPathHelper(node->right,sum,currentSum) + (currentSum == sum);
                                          ^~~~
prog.cpp:7:87: error: request for member ‘right’ in ‘* node’, which is of non-class type ‘int’
             return countPathHelper(node->left,sum,currentSum) + countPathHelper(node->right,sum,currentSum) + (currentSum == sum);
                                                                                       ^~~~~
prog.cpp: In member function ‘int Solution::pathSum(int*, int)’:
prog.cpp:11:20: error: ‘NULL’ was not declared in this scope
         if(root == NULL) return 0;
                    ^~~~
prog.cpp:11:20: note: ‘NULL’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
prog.cpp:12:60: error: request for member ‘right’ in ‘* root’, which is of non-class type ‘int’
         return countPathHelper(root,sum,0) + pathSum(root->right,sum) + pathSum(root->left,sum);
                                                            ^~~~~
prog.cpp:12:87: error: request for member ‘left’ in ‘* root’, which is of non-class type ‘int’
         return countPathHelper(root,sum,0) + pathSum(root->right,sum) + pathSum(root->left,sum);
                                                                                       ^~~~
stdout
Standard output is empty