Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "solution_tree.h"
- #include <vector>
- #include <iostream>
- #include <map>
- using namespace std;
- map<int, int> m;
- bool Solution(const Node* root) {
- if (!root) {
- return true;
- }
- m[root->value]++;
- if (m[root->value] > 1) {
- return false;
- }
- if (root->left && root->left->value > root->value) {
- return false;
- }
- if (root->right && root->right->value < root->value) {
- return false;
- }
- return Solution(root->left) && Solution(root->right);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement