2 approach with great explanation. Beats 84% user.  Recursive and Looping
\n\n# \u2705 \u2B06\uFE0F --- Soln -  1 ---  \u2B06 \u267B\uFE0F\n# \uD83E\uDD29 Intuition and Approach - Recursive \uD83E\uDD73\n\nthe searchBST function is a 
![Screenshot 2023-07-20 234618.png](https://assets.leetcode.com/users/images/266f5967-de24-468f-a32a-2637fee990cb_1689878647.4068298.png)\n\n# \u2705 \u2B06\uFE0F --- Soln -  1 ---  \u2B06 \u267B\uFE0F\n# \uD83E\uDD29 Intuition and Approach - Recursive \uD83E\uDD73\n\nthe searchBST function is a recursive function that searches for a specific target value in a binary search tree (BST). The function starts its search from the root of the BST and traverses down the tree based on the comparison of the target value with the values of nodes. If the target value is found in the tree, the function returns the corresponding TreeNode*, otherwise, it returns NULL to indicate that the target value is not present in the BST.\n\n# Complexity\n- Time complexity: O(log n)\n\n- Space complexity: O(log n)\n\n\n# Code\n```\n\nclass Solution {\npublic:\n    TreeNode* searchBST(TreeNode* root, int target) {\n\n        if(root->val == target) return root;\n\n        //if the target is lesser than the root->val, then \n        else if(root->val > target) return searchBST(root->left,target);\n        else return searchBST(root->right, target);\n\n        // If the root is null (i.e., the tree is empty) or we have reached a leaf node,\n        // we cannot find the target in the tree, so we return null.\n        if (root == NULL) return NULL;\n\n        // If the current node\'s value is equal to the target value,\n        // then we have found the node containing the target value, so we return this node.\n        if (root->val == target) return root;\n\n        // If the target value is lesser than the current node\'s value,\n        // we need to search in the left subtree of the current node.\n        // So we recursively call the searchBST function with the left child of the current node.\n        else if(root->val > target) return searchBST(root->left,target);\n\n        // If the target value is greater than the current node\'s value,\n        // we need to search in the right subtree of the current node.\n        // So we recursively call the searchBST function with the right child of the current node.\n        else return searchBST(root->right, target);\n\n        \n    }\n};\n```\n# \u2B06\uFE0F\u2705---  Soln - 2  --- \uD83E\uDD73\n\n# \uD83E\uDD29 Intuition and Approach \u267B\uFE0F\nwhile loop to traverse the binary search tree iteratively, moving to the left or right subtree based on the comparison of the target value with the values of nodes. If the target value is found in the tree, the function returns the corresponding TreeNode*, otherwise, it returns NULL to indicate that the target value is not present in the BST. \n\n```\n    // The loop continues until either the root becomes NULL (end of the tree) or\n    // the root\'s value matches the target value.\n    while (root != NULL && root->val != target) {\n\n        // If the current node\'s value is greater than the target value,\n        // move to the left subtree to continue the search.\n        if (root->val > target)\n            root = root->left;\n\n        // If the current node\'s value is lesser than the target value,\n        // move to the right subtree to continue the search.\n        else\n            root = root->right;\n    }\n\n    // Return the current node (which contains the target value) if found,\n    // or NULL if the target value is not present in the BST.\n    return root;\n```\n\n
['C', 'C++', 'Java', 'Python3', 'JavaScript']