funcshortestToChar(s string, c byte) []int { result := []int{} for i := range s { if s[i] == c { result = append(result, 0) continue } nowMin := len(s) for j := i+1; j < len(s); j++ { if s[j] == c { if (j-i) < nowMin { nowMin = j-i } break } } for j := i-1; j >= 0; j-- { if s[j] == c { if (i-j) < nowMin { nowMin = i - j } break } } result = append(result, nowMin) } return result }