C++ Easy Solution ✅ || DFS
Complexity\n- Time complexity: O(logn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n#
# Complexity\n- Time complexity: O(logn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    TreeNode* ans;\n    TreeNode* searchBST(TreeNode* root, int val) {\n        if(!root)\n        return root;\n        if(root->val==val)\n            return root;\n        if(root->val>val)\n            ans=searchBST(root->left,val);\n        else if(root->val<val)\n            ans=searchBST(root->right,val);\n        return ans;\n    }\n};\n```\n![9c6f9412-c860-47d6-9a2e-7fcf37ff3321_1686334926.180891.png](https://assets.leetcode.com/users/images/2a03238b-4173-496f-9fb8-5a9e6621f06a_1704268368.0760489.png)\n
['Depth-First Search', 'Binary Search Tree', 'C++']