Leetcode Note: Go - Two Furthest Houses With Different Colors

Two Furthest Houses With Different Colors - LeetCode
https://leetcode.com/problems/two-furthest-houses-with-different-colors/

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

回答

Go - Two Furthest Houses With Different Colors - LeetCode
https://leetcode.com/problems/two-furthest-houses-with-different-colors/solutions/2968965/go/

func maxDistance(colors []int) int {
    max := 0
    for i := 0; i < len(colors) - 1; i++ {
        for j := i + 1; j < len(colors); j++ {
            if colors[i] != colors[j] && j - i > max {
                max = j - i
            }
        }
    }
    return max
}