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

Function searchRange

tasks/34.go:10–36  ·  view source on GitHub ↗
(nums []int, target int)

Source from the content-addressed store, hash-verified

8}
9
10func searchRange(nums []int, target int) []int {
11 ind := len(nums) / 2
12 if len(nums) == 0 {
13 return []int{-1, -1}
14 }
15 if target < nums[ind] {
16 for ; ind >= 0 && target != nums[ind]; ind-- {
17 if target > nums[ind] {
18 return []int{-1, -1}
19 }
20 }
21 if ind < 0 {
22 return []int{-1, -1}
23 }
24 }
25 if target > nums[ind] {
26 for ; ind < len(nums) && target != nums[ind]; ind++ {
27 if target < nums[ind] {
28 return []int{-1, -1}
29 }
30 }
31 if ind >= len(nums) {
32 return []int{-1, -1}
33 }
34 }
35 return expandFromMiddle(&nums, target, ind)
36}
37
38func expandFromMiddle(nums *[]int, target, ind int) []int {
39 right := ind

Callers 1

mainFunction · 0.85

Calls 1

expandFromMiddleFunction · 0.85

Tested by

no test coverage detected