Advertisement
lazar955

Untitled

Oct 22nd, 2023
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. func search(nums []int, target int) int {
  2. low,high:=0, len(nums) -1
  3. var mid int
  4. for low<=high {
  5. mid = (low+high)/2
  6. if nums[mid] <target {
  7. low = mid+1
  8. }else if nums[mid] > target {
  9. high = mid - 1
  10. }else {
  11. return mid
  12. }
  13. }
  14. return -1
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement