fork download
  1. class Solution {
  2. public:
  3. int max_ans = INT_MIN;
  4. int solve(TreeNode *root){
  5.  
  6. if (!root) {
  7. return 0;
  8. }
  9. int left_ans = maxPathSum(root->left);
  10. int right_ans = maxPathSum(root->right);
  11. max_ans = max(max_ans,root->val);
  12. max_ans = max(max_ans,left_ans+root->val);
  13. max_ans = max(max_ans,right_ans+root->val);
  14. max_ans = max(max_ans,root->val + left_ans + right_ans );
  15. return max(root->val,max(left_ans + root->val, right_ans + root->val));
  16.  
  17. }
  18. int maxPathSum(TreeNode* root) {
  19. solve(root);
  20. return max_ans;
  21. }
  22. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:2: error: illegal start of type
public:
      ^
Main.java:4: error: <identifier> expected
int solve(TreeNode *root){
                  ^
Main.java:18: error: <identifier> expected
int maxPathSum(TreeNode* root) {
                       ^
3 errors
stdout
Standard output is empty