Leetcode Note: Go - Detect Pattern of Length M Repeated K or More Times

Detect Pattern of Length M Repeated K or More Times - LeetCode
https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times/

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

回答

Go solution 100%, 100% with image - Detect Pattern of Length M Repeated K or More Times - LeetCode
https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times/solutions/1082801/go-solution-100-100-with-image/

func containsPattern(arr []int, m int, k int) bool {
    counter := 0

    for i := 0; i < len(arr) - m; i++ {
        if arr[i] != arr[i+m] {
            counter = 0
        } else {
            counter++
        }

        if counter == (k-1)*m {
            return true
        }
    }

    return false
}