Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int helper(TreeNode* root, int& max) {
- if (root == NULL) {
- return 0;
- }
- int left = helper(root->left, max);
- int right = helper(root->right, max); // step 1
- left = left < 0 0 : left; // step 2
- right = right < 0 0 : right;
- max = max > (root->value + left + right) max : (root->value + left + right);
- return left > right (left + root->value) : (right + root->value); // step 3
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement