(arr []int, target int)
| 3 | import "math" |
| 4 | |
| 5 | func Jump2(arr []int, target int) (int, error) { |
| 6 | step := int(math.Round(math.Sqrt(float64(len(arr))))) |
| 7 | rbound := len(arr) |
| 8 | for i := step; i < len(arr); i += step { |
| 9 | if arr[i] > target { |
| 10 | rbound = i |
| 11 | break |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | for i := rbound - step; i < rbound; i++ { |
| 16 | if arr[i] == target { |
| 17 | return i, nil |
| 18 | } |
| 19 | if arr[i] > target { |
| 20 | break |
| 21 | } |
| 22 | } |
| 23 | return -1, ErrNotFound |
| 24 | } |
no outgoing calls