Created
April 2, 2018 16:32
-
-
Save gearnode/741fb6b7dec8d6a802bc0ad80e7a8ac3 to your computer and use it in GitHub Desktop.
haveSumWithPair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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