Advertisement
Derga

Untitled

Sep 10th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include "solution_tree.h"
  2. #include <vector>
  3. #include <iostream>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. map<int, int> m;
  9.  
  10. bool Solution(const Node* root) {
  11.     if (!root) {
  12.         return true;
  13.     }
  14.    
  15.     m[root->value]++;
  16.     if (m[root->value] > 1) {
  17.         return false;
  18.     }
  19.  
  20.     if (root->left && root->left->value > root->value) {
  21.         return false;
  22.     }
  23.  
  24.     if (root->right && root->right->value < root->value) {
  25.         return false;
  26.     }
  27.  
  28.     return Solution(root->left) && Solution(root->right);
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement