题目:https://leetcode-cn.com/problems/video-stitching/
分析:其实这道题,我只想说,这语文也太难懂了,看了半天晕晕乎乎不知道题目啥意思。
其实题目意思是,给了一个二维数组 clips,一个 int 类型的 T
问,能不能用二维数组,组成一个 一维数组,这个数组为[0,T],如果可以,返回需要二维数组中的最少 子数组 数量。否自返回-1
代码:
public int videoStitching(int[][] clips, int T) {
int[] dp = new int[T+1];
Arrays.fill(dp,Integer.MAX_VALUE-1);
dp[0] = 0;
for (int i=1;i<=T;i++){
for (int[] clip:clips){
if (clip[0]<i && i<clip[1]){
dp[i] = Math.min(dp[i],dp[clip[0]]+1);
}
}
}
return dp[T] == Integer.MAX_VALUE-1 ? -1:dp[T];
}