👍Runtime 292 ms Beats 100.00%
Code\n\nfunc countExcellentPairs(nums []int, k int) int64 {\n\tmapBitsCount := make(map[int]map[int]struct{})\n\tfor _, num := range nums {\n\t\tbitCount := bit
# Code\n```\nfunc countExcellentPairs(nums []int, k int) int64 {\n\tmapBitsCount := make(map[int]map[int]struct{})\n\tfor _, num := range nums {\n\t\tbitCount := bits.OnesCount(uint(num))\n\t\tif mapBitsCount[bitCount] == nil {\n\t\t\tmapBitsCount[bitCount] = make(map[int]struct{})\n\t\t}\n\t\tmapBitsCount[bitCount][num] = struct{}{}\n\t}\n\n\tvar ans int64\n\tvisited := make(map[int]struct{})\n\tfor _, num := range nums {\n\t\tif _, ok := visited[num]; ok {\n\t\t\tcontinue\n\t\t}\n\t\tneed := max(0, k-bits.OnesCount(uint(num)))\n\t\tfor key, set := range mapBitsCount {\n\t\t\tif key >= need {\n\t\t\t\tans += int64(len(set))\n\t\t\t}\n\t\t}\n\t\tvisited[num] = struct{}{}\n\t}\n\n\treturn ans\n}\n\nfunc max(a, b int) int {\n\tif a > b {\n\t\treturn a\n\t}\n\treturn b\n}\n\n```
['Go']