1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| class Solution { 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) { int a = clip[0]; int b = clip[1]; if (i >= a && i <= b) { dp[i] = Math.min(dp[i], dp[a] + 1); } } } return dp[T] == Integer.MAX_VALUE-1 ? -1 : dp[T]; } }
|