Skip to content

Instantly share code, notes, and snippets.

@gearnode
Created April 2, 2018 16:32
Show Gist options
  • Save gearnode/741fb6b7dec8d6a802bc0ad80e7a8ac3 to your computer and use it in GitHub Desktop.
Save gearnode/741fb6b7dec8d6a802bc0ad80e7a8ac3 to your computer and use it in GitHub Desktop.
haveSumWithPair
package main
import (
"fmt"
)
func haveSumWithPair(list []int, sum int) bool {
i := 0
y := len(list) - 1
for i < y {
res := list[i] + list[y]
if res == 8 {
return true
} else if res < 8 {
i++
} else {
y--
}
}
return false
}
func main() {
res := haveSumWithPair([]int{1, 3, 4, 5, 7}, 8)
fmt.Println("Result =>", res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment