Easy Java Code || Beats 100%
Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(1)\n# Code\n\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int va
# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(1)\n# Code\n```\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 val) {\n        if(root == null)  return null;\n        if(root.val == val) return root;\n\n        if(val < root.val){\n            return searchBST(root.left, val);\n        }else {\n            return searchBST(root.right, val);\n        }\n    }\n}\n```\n\n![upvote.jpeg](https://assets.leetcode.com/users/images/1aa72468-3b35-4cae-bd7b-6ff2ec2c7ddb_1705760682.8464684.jpeg)\n
['Binary Search Tree', 'Java']