Created
May 2, 2014 04:51
-
-
Save narusemotoki/6d2afb629ecc3f3aa184 to your computer and use it in GitHub Desktop.
This is my first time go without hello world.
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" | |
"sort" | |
) | |
func mode(arr []int) int { | |
sort.Ints(arr) | |
var mode_count, mode_value, current_count, current_value int | |
for _, a := range arr { | |
if a != current_value { | |
current_value, current_count = a, 0 | |
} | |
current_count++ | |
if mode_count < current_count { | |
mode_value, mode_count = current_value, current_count | |
} | |
} | |
return mode_value | |
} | |
func main() { | |
fmt.Println(mode([]int{1, 2, 2, 3, 3, 3, 2, 2})) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment