Created
December 23, 2015 15:46
-
-
Save GrimTheReaper/858c852f6c143c15dd22 to your computer and use it in GitHub Desktop.
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 main() { | |
lg, positions := largestNumber([]int{71, 114, 105, 109, 84, 104, 101, 82, 101, 97, 112, 101, 114}) | |
fmt.Printf("Largest Number: %v\n", lg) | |
fmt.Print("Positions: ") | |
for _, v := range positions { | |
fmt.Printf("%v ", v) | |
} | |
fmt.Println() | |
} | |
func largestNumber(na []int) (lg int, positions []int) { | |
for i, v := range na { | |
if v == lg { | |
positions = append(positions, i) | |
} | |
if v > lg { | |
lg = v | |
positions = []int{i} | |
} | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Play with it: http://play.golang.org/p/0khLpSMOVU