Leetcode Note: Go - Find Lucky Integer in an Array

Find Lucky Integer in an Array - LeetCode
https://leetcode.com/problems/find-lucky-integer-in-an-array/

  • Go 言語で取り組んだメモ

回答

Go solutions using array or map: 4 ms, 3.1 MB - Find Lucky Integer in an Array - LeetCode
https://leetcode.com/problems/find-lucky-integer-in-an-array/solutions/824972/go-solutions-using-array-or-map-4-ms-3-1-mb/

func findLucky(arr []int) int {
    frq := make(map[int]int)
    for i := 0; i < len(arr); i++ {
        frq[arr[i]]++
    }
    maxLucky := -1
    for k, v := range frq  {
        if k == v && k > maxLucky  {
            maxLucky = k
        }
    }
    return maxLucky
}