Created
July 15, 2019 22:54
-
-
Save piyushdec/0644beb7997abfd53aa646ed57074ca2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| func searchBST(_ root: TreeNode?, _ val: Int) -> TreeNode? { | |
| guard let node = root else { return nil } | |
| if node.val == val { return root } | |
| if node.val > val { return searchBST(node.left, val) } | |
| if node.val < val { return searchBST(node.right, val) } | |
| return nil | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment