Simple intuitive, beats 100%, O(1) time for FindElements, O(log(n)) time for Find and O(1) space
IntuitionWe can use binary representation oftargetto go through the tree.ApproachThe key idea is usingtargetbinary representation to understand where to go in t
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We can use binary representation of `target` to go through the tree.

# Approach
<!-- Describe your approach to solving the problem. -->
The key idea is using `target` binary representation to understand where to go in the tree to the left or to the right.

The tree will always look like this

![target (1).png](https://assets.leetcode.com/users/images/82f053ce-e916-4967-abc7-4f87a144caf3_1740141798.74788.png)

We may notice that the binary representation of `target + 1` value is very clear:
each bit shows where to go it the tree `0` -> `left` and `1` -> `right`

For example, lets find `11`. Binary for `target + 1` is `1100`
We always ignore the first bit (it is always 1, see the picture) and other bits are `100` mean go `right->left->left` starting from the root to check if node exists. 


# Complexity
- Time complexity: O(1) for FindElements, O(log(n)) for Find
<!-- Add your time complexity here, e.g. $$O(n)$$ -->


- Space complexity: O(1) for all methods
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```golang []
/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
type FindElements struct {
    root *TreeNode
}


func Constructor(root *TreeNode) FindElements {
    // simple store the root 
    res := FindElements{root: root}
    return res
}


func (this *FindElements) Find(target int) bool {
    node := this.root
    // calculate the mask to iterate over target bits 
    // from the left to the right
    mask := 1
    num := target + 1
    for num != 0 {
        num >>= 1
        mask <<= 1
    }
    mask >>= 1
    num = (target + 1) & (mask - 1)
    mask >>= 1
    for mask != 0 {
        if num & mask == 0 {
            if node.Left == nil {
                return false
            }
            node = node.Left 
        } else {
            if node.Right == nil {
                return false
            }
            node = node.Right
        }
        mask >>= 1
    }
    return true
}


/**
 * Your FindElements object will be instantiated and called as such:
 * obj := Constructor(root);
 * param_1 := obj.Find(target);
 */
```
['Go']