【1024. 视频拼接】贪心
class Solution { public static void main(String[] args) { Solution solution = new Solution(); int ans = solution.videoStitching(new int[][]{ {8,10},{17,39},{18,19},{8,16},{13,35},{33,39},{11,19},{18,35} },20); System.out.println(ans); } public int videoStitching(int[][] clips, int time) { int len = clips.length; int t = time; boolean first = true; int ans = 0; while (t != 0) { int index = selectOne(clips,t,first); if (index == -1){ return -1; } first = false; t = clips[index][0]; ans++; } return ans; } public int selectOne(int[][] clips,int t,boolean first){ int dis = Integer.MAX_VALUE; int ans = -1; for(int i = 0;i<clips.length;i++){ int[] arr = clips[i]; if(arr[1] >= t && ( (first && arr[0] <= t) || (!first && arr[0] < t) )&& arr[0] < dis) { dis = arr[0]; ans = i; } } return ans; } }
本文作者:love
本文链接:https://www.cnblogs.com/fishcanfly/p/16351056.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步