Leetcode Note: Go - String Matching in an Array

String Matching in an Array - LeetCode
https://leetcode.com/problems/string-matching-in-an-array/

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

回答

Go brute force - String Matching in an Array - LeetCode
https://leetcode.com/problems/string-matching-in-an-array/solutions/2482659/go-brute-force/

func stringMatching(words []string) []string {
    wordSet := make(map[string]struct{})
    
    for i := 0; i < len(words); i++ {
        for j := 0; j < len(words); j++ {
            if i != j && strings.Contains(words[i], words[j]) {
                wordSet[words[j]] = struct{}{}
            }
        }
    }
    
    var res []string
    
    for k, _ := range wordSet {
        res = append(res, k)
    }
    
    return res
}