G2A Many GEOs


a guest Apr 6th, 2020 159 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution{
  2.     private:
  3.         void visibleNodesUtil(Tree *root, int greater, vector<int> &nodes){
  4.             if(!root) return;
  5.             if(root->val > greater) nodes.push_back(root->val);
  6.             visibleNodesUtil(root->left, max(greater, root->val), nodes);
  7.             visibleNodesUtil(root->right, max(greater, root->val), nodes);
  8.         }
  9.     public:
  10.         vector<int> visibleNodes(Tree *root){
  11.             vector<int> nodes;
  12.             visibleNodesUtil(root, INT_MIN, nodes);
  13.             sort(nodes.begin(), nodes.end());
  14.             return nodes;
  15.         }
  16. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand