Easy and simple Approach | Beats 100%
Intuition\nThe problem involves searching for a target value in a BST:\n- If the current node is null, then the target value does not exist in the tree, so we r
## Intuition\nThe problem involves searching for a target value in a BST:\n- If the current node is null, then the target value does not exist in the tree, so we return null.\n- If the current node\'s value matches the target, we return the current node.\n- If the target value is less than the current node\'s value, we recursively search in the left subtree.\n- If the target value is greater than the current node\'s value, we recursively search in the right subtree.\n\n## Approach\nThe approach leverages the properties of a BST:\n- If the current node is null, the target cannot be found, so we return null.\n- If the current node\'s value matches the target, we return the current node.\n- Depending on whether the target is less than or greater than the current node\'s value, we recursively search in the left or right subtree, respectively.\n\n## Complexity\n- **Time complexity:** In the worst case, the time complexity is \\(O(h)\\), where \\(h\\) is the height of the BST. This is because in the worst case, we might need to traverse the height of the tree.\n- **Space complexity:** The space complexity is \\(O(h)\\) due to the recursion stack, where \\(h\\) is the height of the BST. In the worst case, the recursion stack could be as deep as the height of the tree.\n\n## Code\n```java\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\nclass Solution {\n    public TreeNode searchBST(TreeNode root, int target) {\n        if (root == null) {\n            return null;\n        }\n        if (root.val == target) {\n            return root;\n        }\n        if (target < root.val) {\n            return searchBST(root.left, target);\n        } else {\n            return searchBST(root.right, target);\n        }\n    }\n}\n```\n
['Java']