Skip to content

Instantly share code, notes, and snippets.

@GrimTheReaper
Created December 23, 2015 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrimTheReaper/858c852f6c143c15dd22 to your computer and use it in GitHub Desktop.
Save GrimTheReaper/858c852f6c143c15dd22 to your computer and use it in GitHub Desktop.
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
}
@GrimTheReaper
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment