• + 0 comments

    go

    func matchingStrings(stringList []string, queries []string) []int32 {
    	// Write your code here
    	var ans = make([]int32, len(queries), len(queries))
    	if len(stringList) == 0 || len(queries) == 0 {
    		return ans
    	}
    	var sl = make(map[string]int32, len(stringList))
    	for _, s := range stringList {
    		if _, found := sl[s]; found {
    			sl[s]++
    		} else {
    			sl[s] = 1
    		}
    	}
    	for i, q := range queries {
    		if v, found := sl[q]; found {
    			ans[i] = v
    		}
    	}
    	fmt.Println(ans)
    	return ans
    }