Skip to content

Instantly share code, notes, and snippets.

@piyushdec
Created July 15, 2019 22:54
Show Gist options
  • Select an option

  • Save piyushdec/0644beb7997abfd53aa646ed57074ca2 to your computer and use it in GitHub Desktop.

Select an option

Save piyushdec/0644beb7997abfd53aa646ed57074ca2 to your computer and use it in GitHub Desktop.
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