You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: a.go
    path of file: ./repos/codeforces-go/leetcode/weekly/268/a
    
    the code of the file until where you have to start completion: package main

/* O(n) 做法

先判断最左右的两栋房子颜色是否相同
    
func maxDistance(colors []int) (ans int) {
	n := len(colors)
	c := colors[0]
	if c != colors[n-1] { return n - 1 }
	l, r := 1, n-2
	for colors[l] == c { l++ }
	for colors[r] == c { r-- }
	return max(r, n-1-l)
}