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: Solution.go
    path of file: ./repos/awesome-golang-algorithm/leetcode/401-500/0495.Teemo-Attacking
    
    the code of the file until where you have to start completion: package Solution

func Solution(timeSeries []int, duration int) int {
	ans, length := 0, len(timeSeries)
	if length == 0 {
		return ans
	}
	end := timeSeries[0] + duration - 1
    
func Solution(timeSeries []int, duration int) int {
	ans, length := 0, len(timeSeries)
	if length == 0 {
		return ans
	}
	end := timeSeries[0] + duration - 1
	ans += duration
	for idx := 1; idx < length; idx++ {
		if timeSeries[idx] <= end {
			ans -= end - timeSeries[idx] + 1
		}
		end = timeSeries[idx] + duration - 1
		ans += duration
	}
	return ans
}