Skip to content

Instantly share code, notes, and snippets.

@CollinShoop
Last active January 23, 2022 04:06
Show Gist options
  • Save CollinShoop/b1d00b134e822e3deaa4bef42d39506c to your computer and use it in GitHub Desktop.
Save CollinShoop/b1d00b134e822e3deaa4bef42d39506c to your computer and use it in GitHub Desktop.
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func searchBST(root *TreeNode, val int) *TreeNode {
if root == nil || root.Val == val {
return root
}
if val < root.Val {
return searchBST(root.Left, val)
}
return searchBST(root.Right, val)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment