Skip to content

Commit

Permalink
Time: 0 ms (100%), Space: 4.3 MB (14.25%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Nov 29, 2024
1 parent 0a91dfc commit e7edbf2
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
func search(nums []int, target int) int {
l, r := 0, len(nums) - 1
for l <= r {
m := (l + r) / 2
if target == nums[m] {
return m
}

if nums[l] <= nums[m] {
if target > nums[m] || target < nums[l] {
l = m + 1
} else {
r = m - 1
}
} else {
if target < nums[m] || target > nums[r] {
r = m - 1
} else {
l = m + 1
}
}
}

return -1
}

0 comments on commit e7edbf2

Please sign in to comment.