当前位置:网站首页>0 dynamic planning leetcode1024. Video splicing

0 dynamic planning leetcode1024. Video splicing

2022-07-23 12:53:00 18 ARU

analysis

Dynamic programming
dp[i] From 0 To i Seconds requires at least a few pieces of material .
dp[i] = Math.min(dp[i],dp[ Left endpoint of a material ]+1);
dp[i] The value concept of is to traverse all the materials containing the current second , Select from 0 To i The material that needs the least material .

class Solution {
    
    public int videoStitching(int[][] clips, int time) {
    
int[] dp = new int[time+1];
        Arrays.fill(dp, time+1);
        dp[0] = 0;
        for (int i = 1; i <= time; i++) {
    
            for (int j = 0; j < clips.length; j++) {
    
                if (clips[j][0] <= i && clips[j][1] >= i) {
    
                    dp[i] = Math.min(dp[i],dp[clips[j][0]]+1);
                }
            }
        }
        if (dp[time] > time) {
    
            return -1;
        }
        return dp[time];

    }
}
原网站

版权声明
本文为[18 ARU]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230539559372.html