⭐Simplest Python solution using Recursion in 7 lines of code.
Intuition\nOn seeing this problem initially, I instantly thought of applying recursion by searching through the root node and recursively calling the function f
# Intuition\nOn seeing this problem initially, I instantly thought of applying recursion by searching through the root node and recursively calling the function for left and right subtrees until we reach the leaf nodes.\n\n# Approach\n* First, we check if the root is not None. This acts as the base case for the recursive algorithm.\n* Then we have three cases:\n  * Value of the root = target\n  * Value of the root > target\n  * Value of the root < target\n* If the root value is greater than the target, then we recursively call the function for the left subtree, since it is guaranteed not to be present in the right subtree.\n* Similarly, If the root value is less than the target, then we recursively call the function for the right subtree, since it is guaranteed not to be present in the left subtree.\n* If the root value equals the target, then we return the root.\n* As for unsuccessful cases, the while loop terminates when the root is None and then returns nothing, basically None.\n\n# Complexity\n- Time complexity: \n  - Average case: $$O(logn)$$\n  - Best case: $$O(1)$$ (When the root itself is the target)\n  - Worst case: $$O(n)$$ (When the BST is skewed and takes maximum \'n\' traversals)\n  \n\n- Space complexity (call stack):\n  - Average case: $$O(logn)$$\n  - Best case: $$O(1)$$ (When the root itself is the target)\n  - Worst case: $$O(n)$$ (When the BST is skewed and takes maximum \'n\' traversals, hence \'n\' function calls)\n\n# Code\n```python\n# Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\n\nclass Solution:\n    def searchBST(self, root: Optional[TreeNode], val: int) -> Optional[TreeNode]:\n        if root:\n            if root.val < val:\n                return self.searchBST(root.right, val)\n            elif root.val > val:\n                return self.searchBST(root.left, val)\n            else:\n                return root\n\n```
['Python3']