Leetcode Note: Go - Count Items Matching a Rule
Count Items Matching a Rule - LeetCode
https://leetcode.com/problems/count-items-matching-a-rule/
- Go 言語で取り組んだメモ
回答
Intuitive, Go Solution - Count Items Matching a Rule - LeetCode
https://leetcode.com/problems/count-items-matching-a-rule/solutions/1540350/intuitive-go-solution/
func countMatches(items [][]string, ruleKey string, ruleValue string) int {
hashMap := make(map[string]int)
hashMap["type"] = 0
hashMap["color"] = 1
hashMap["name"] = 2
var res int
for _, item := range items {
if item[hashMap[ruleKey]] == ruleValue {
res++
}
}
return res
}