k.go 311 B

123456789101112131415161718
  1. package kata
  2. func HighestRank(nums []int) int {
  3. counts := make(map[int]int)
  4. for _, num := range nums {
  5. counts[num]++
  6. }
  7. maxNum, maxCount := -1, 0
  8. for num, count := range counts {
  9. if count > maxCount || (count == maxCount && num > maxNum) {
  10. maxCount = count
  11. maxNum = num
  12. }
  13. }
  14. return maxNum
  15. }