1class Solution: 2 def helper(self,l,r,clips)->int: 3 maxL,maxR=0,0 4 iL,iR=-1,-1 5 for i,c in enumerate(clips): 6 if c[0]<=l and c[1]>=r: 7 return 1 8 if c[0]<=l: 9 if c[1]-l>maxL: 10 maxL=c[1]-l 11 iL=i 12 if c[1]>=r: 13 print(r,c[0],c[1],maxR) 14 if r-c[0]>maxR: 15 maxR=r-c[0] 16 iR=i 17 if iL==-1 or iR==-1: 18 return -1 19 20 new_l=clips[iL][1] 21 new_r=clips[iR][0] 22 if clips[iL][0]==clips[iR][0] and clips[iL][1]==clips[iR][1]: 23 return 1 24 if new_l>=new_r: 25 return 2 26 clips=[c for i,c in enumerate(clips) if i not in (iL,iR)] 27 return 2+self.helper(new_l,new_r,clips) 28 29 30 def videoStitching(self, clips: List[List[int]], T: int) -> int: 31 return self.helper(0,T,clips)
Leetcode 1024. Video Stitching
Stella981
2021-10-11
1033 0 0
点赞
收藏
评论区
加载中...