MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / search

Function search

tasks/33.go:7–23  ·  view source on GitHub ↗
(nums []int, target int)

Source from the content-addressed store, hash-verified

5}
6
7func search(nums []int, target int) int {
8 if nums[0] <= target {
9 for i := 0; i <= len(nums)-1 && nums[i] <= target; i++ {
10 if nums[i] == target {
11 return i
12 }
13 }
14 return -1
15 }
16
17 for i := len(nums) - 1; i >= 0 && nums[i] >= target; i-- {
18 if nums[i] == target {
19 return i
20 }
21 }
22 return -1
23}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected