From b1a2b7d1f6e6e569ccdfd3b14ff8d1cb959c6e83 Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Wed, 23 Dec 2020 19:33:12 -0800 Subject: [PATCH] Update 1024.Video-Stitching.cpp --- .../1024.Video-Stitching.cpp | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/Greedy/1024.Video-Stitching/1024.Video-Stitching.cpp b/Greedy/1024.Video-Stitching/1024.Video-Stitching.cpp index 51ba28a6c..761ed1e1a 100644 --- a/Greedy/1024.Video-Stitching/1024.Video-Stitching.cpp +++ b/Greedy/1024.Video-Stitching/1024.Video-Stitching.cpp @@ -1,40 +1,38 @@ class Solution { static bool cmp(vector&a, vector&b) { - if (a[0]==b[0]) - return a[1]>b[1]; - else + if (a[0]!=b[0]) return a[0]b[1]; } public: int videoStitching(vector>& clips, int T) { - sort(clips.begin(),clips.end(),cmp); + if (T==0) return 0; + sort(clips.begin(),clips.end(),cmp); - if (clips[0][0]!=0) return -1; - int right = clips[0][1]; - int idx = 0; - int count = 1; - if (clips[0][1]>=T) return count; - - while (idx < clips.size()) - { - int farReach = right; - while (idx=T) return count; - right = farReach; - } - - return -1; - + + if (nextFar >= T) + return count; + else if (nextFar == far) + return -1; + far = nextFar; + } + + return -1; } };