Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int sumTree (BTNode* root)
- {
- if (root == NULL) return 0;
- return root->val + sumTree(root->left) + sumTree(root->right);
- }
- int distinctParities(BTNode* root) {
- if (root == NULL) return 0;
- if (root->left == NULL) return distinctParities(root->right);
- if (root->right == NULL) return distinctParities(root->left);
- int sumLeft = sumTree(root->left);
- int sumRight = sumTree(root->right);
- if ((sumLeft % 2) + (sumRight % 2) % 2 == 1) return 1 + distinctParities(root->left) + distinctParities(root->right) ;
- return distinctParities(root->left) + distinctParities(root->right);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement