Leetcode Note: Go - Occurrences After Bigram

Occurrences After Bigram - LeetCode
https://leetcode.com/problems/occurrences-after-bigram/

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

回答

Golang Solution streaming or split string - LeetCode Discuss
https://leetcode.com/problems/occurrences-after-bigram/discuss/1847428/Golang-Solution-streaming-or-split-string

func findOcurrences(text string, first string, second string) []string {
    if len(first) + len(second) >= len(text) {
        return []string{}
    }
    
    res := []string{}
    
    ss := strings.Split(text, " ")

    for i := 0; i < len(ss) - 2; i++ {
        if ss[i] == first && ss[i+1] == second {
            res = append(res, ss[i+2])
        }
    }
    
    return res
}