leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1261.cpp (658B)


0 class FindElements { 1 TreeNode *root; 2 unordered_set<int> all; 3 4 public: 5 FindElements(TreeNode *root) : root(root) { 6 queue<TreeNode *> q({root}); 7 root->val = 0; 8 while (!q.empty()) { 9 TreeNode *root = q.front(); 10 q.pop(); 11 all.insert(root->val); 12 if (root->left) { 13 root->left->val = 2 * root->val + 1; 14 q.push(root->left); 15 } 16 if (root->right) { 17 root->right->val = 2 * root->val + 2; 18 q.push(root->right); 19 } 20 } 21 } 22 23 bool find(int target) { return all.count(target); } 24 };