Easy python O(log target) solution with O(1) space [binary search]
IntuitionThe solution is inspired from the binary search method followed in https://leetcode.com/problems/count-complete-tree-nodes/editorialApproachWhen the no
# Intuition
The solution is inspired from the binary search method followed in https://leetcode.com/problems/count-complete-tree-nodes/editorial 

# Approach
When the nodes are numbered from 1 to n in a binary tree, we can check the existence of any node using the technique similar to binary search. This would take O(log(target)) time complexity.

From the editorial shared above:

    How to check if the node number idx exists?
    Let's use binary search again to reconstruct the sequence of moves
    from root to idx node. For example, idx = 4. idx is in the
    second half of nodes 0,1,2,3,4,5,6,7 and hence the first move is to the right. 

    Then idx is in the first half of nodes 4,5,6,7 and hence
    the second move is to the left. The idx is in the first half of nodes
    4,5 and hence the next move is to the left. The time complexity
    for one check is O(d).

![image.png](https://assets.leetcode.com/users/images/81951514-c13e-4057-93a3-6a7e5b25cd2e_1739474021.8802235.png)

 
I just modified the above logic to stop at the level where the target is supposed to be instead of checking till the leaf node. 

# Complexity
# Time complexity:**O(log(target))** 
Since we only check till the depth where target node is supposed to be. 
For a complete tree, this would be O(log H). A skewed tree would O(n) in the worst case.

# Space complexity: O(1)

# Code
```python3 []

class FindElements:

    def __init__(self, root: Optional[TreeNode]):
        self._root = root                

    def find(self, target: int) -> bool:
        root = self._root
        # starting the node numbering from 1 instead of 0 
        # for easy calculation
        target += 1
        depth = math.floor(math.log(target, 2))
        left, right = math.pow(2, depth), math.pow(2, depth+1)-1
        while depth and root:                        
            mid = (left+right)//2
            if target <= mid:
                root = root.left
                right = mid
            else:
                left = mid+1
                root = root.right
            depth -= 1
        return root != None

```
['Binary Search', 'Binary Tree', 'Python3']