✅ 2 Different types of solutions✅||Loop VS Recursion|| Brute Force ➡️Optimization ||
\uD83D\uDE0APlease UPVOTE\uD83D\uDE0A\n# Intuition 1\nTo search for a node with a specific value in a binary search tree (BST), we can leverage the properties o
### \uD83D\uDE0APlease UPVOTE\uD83D\uDE0A\n# Intuition 1\nTo search for a node with a specific value in a binary search tree (BST), we can leverage the properties of the BST. We start from the root and traverse the tree while comparing the value of each node with the target value. If the current node\'s value matches the target value, we return the node. If the current node\'s value is greater than the target value, we move to the left subtree; otherwise, we move to the right subtree.\n\n# Approach\nWe\'ll implement an iterative approach to search for the target value in the BST. We\'ll start from the root and traverse the tree until we find a node with the target value or reach a leaf node. We\'ll compare the value of each node with the target value and adjust our traversal direction accordingly.\n\n# Complexity\n- Time complexity: O(h), where h is the height of the BST. In the worst case, the height of the BST can be O(n), where n is the number of nodes. However, for balanced BSTs, the time complexity is O(log n).\n- Space complexity: O(1) as we\'re not using any extra space apart from a few variables for traversal. \n\n```cpp\nclass Solution {\npublic:\n    TreeNode* searchBST(TreeNode* root, int val) {\n        while (root != nullptr) {\n            if (root->val == val) {\n                return root; // Found the node with the value\n            } else if (root->val > val) {\n                root = root->left; // Move to the left subtree\n            } else {\n                root = root->right; // Move to the right subtree\n            }\n        }\n        return nullptr; // Node with the given value not found\n    }\n};\n```\n# Intuition\nThe problem involves searching for a node with a specific value in a binary search tree (BST). \n\n# Approach 2\nWe use a recursive approach to traverse the BST. Starting from the root, we compare the value of the current node with the target value. If the current node\'s value matches the target value or if the current node is null, we return the current node. If the target value is less than the current node\'s value, we recursively search the left subtree; otherwise, we recursively search the right subtree.\n\n# Complexity\n- Time complexity: $$O(h)$$, where $$h$$ is the height of the tree in the worst case. For a balanced BST, the time complexity is $$O(\\log n)$$, where $$n$$ is the number of nodes.\n- Space complexity: $$O(h)$$, where $$h$$ is the height of the tree. This space is used for the function call stack during recursion.\n\n# Code\n```cpp\nclass Solution {\npublic:\n    TreeNode* searchBST(TreeNode* root, int val) {\n        if (root == nullptr || root->val == val) {\n            return root;\n        }\n        if (root->val > val) {\n            return searchBST(root->left, val);\n        } else {\n            return searchBST(root->right, val);\n        }\n    }\n};\n```\n### \uD83D\uDE0APlease UPVOTE\uD83D\uDE0A\n![upvote.jpeg](https://assets.leetcode.com/users/images/b1cc5e97-9ab9-4f39-936b-26f139dc74c1_1709214939.1174283.jpeg)\n\n
['C++']