Leetcode Note: Go - Intersection of Multiple Arrays

Intersection of Multiple Arrays - LeetCode
https://leetcode.com/problems/intersection-of-multiple-arrays/

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

回答

Funny solution with Go - Intersection of Multiple Arrays - LeetCode
https://leetcode.com/problems/intersection-of-multiple-arrays/solutions/2458233/funny-solution-with-go/

func intersection(nums [][]int) []int {
    numSet := make([]int, 1001)
    
    for i := 0; i < len(nums); i++ {
        for j := 0; j < len(nums[i]); j++ {
            numSet[nums[i][j]]++
        }
    }
    
    var res []int
    
    for i := 0; i < 1001; i++ {
        if numSet[i] == len(nums) {
            res = append(res, i)
        }
    }
    
    sort.Ints(res)
    
    return res
}