1024. 视频拼接

func videoStitching(clips [][]int, time int) int {
    const inf = math.MaxInt64 - 1
    dp := make([]int, time+1)
    for i := range dp {
        dp[i] = inf
    }
    dp[0] = 0
    for i := 1; i < len(dp); i++ {
        for _, clip := range clips {
            l, r := clip[0], clip[1]
            if i<=r && i>l && dp[i] > dp[l] +1 {
                dp[i] = dp[l] + 1
            }
        }
    }
    if dp[time] == inf {
        return -1
    }
    return dp[time]
}

你可能感兴趣的:(1024. 视频拼接)