[C++] Concise and Simple solution 100% | Easy to understand | Recursion and Iteration
Approach 1 :\n Describe your approach to solving the problem. \nIterative Search by comparing values until you encounter a NULL node or Required Node.\n# Comple
# Approach 1 :\n<!-- Describe your approach to solving the problem. -->\nIterative Search by comparing values until you encounter a NULL node or Required Node.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n**O(h)** --> h is height of the BST\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n**O(1)**\n# Code\n```\nclass Solution {\npublic:\n    TreeNode* searchBST(TreeNode* root, int val) {\n        while (root != nullptr && root->val != val) {\n            root = (root->val > val) ? root->left : root->right;\n        }\n        return root;\n    }\n};\n```\n\n---\n\n# Approach 2 :\n<!-- Describe your approach to solving the problem. -->\nRecursively Search by comparing values and return node when condition satisfied.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n**O(h)** --> h is height of the BST\n**O(n)** --> worst case it will have only 1 node in every level. (Linked List case)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n**O(h)** --> h is height of the BST\n\n# Code\n```\nclass Solution {\npublic:\n    TreeNode* searchBST(TreeNode* root, int val) {\n        if(!root) return NULL;\n        if(root->val == val) return root;\n        else if(root->val < val) return searchBST(root->right, val);\n        else return searchBST(root->left, val);\n    }\n};\n```\n\n**Feel free to ask any question in the comment section.\nIf you like this solution, do UPVOTE.**
['Recursion', 'C', 'Iterator', 'C++']