re: Challenge: Get Closest Number in an Array VIEW POST

FULL DISCUSSION
 
package main


import (
        "fmt"
        "sort"
)

func main() {
        l := []int{100, 200, 400, 800, 901, 1600, 3200, 6400, 128000}
        target := 900
        n := sort.SearchInts(l, target)
        if l[n]-target < target-l[n-1] {
                n += 1
        }
        fmt.Printf("%d\n", l[n-1])
}

play.golang.org/p/xxzN4y-fPF0

code of conduct - report abuse