【leetcode 贪婪算法 C++】1024. Video Stitching

1024. Video Stitching

在这里插入图片描述

class Solution {
    
    
public:
    int videoStitching(vector<vector<int>>& clips, int T) {
    
    
        vector<int> V(T+1, 0);
        for(int ii = 0; ii < clips.size(); ii++) {
    
    
            auto A = clips[ii];
            for(int jj = A[0]; jj <= A[1] && jj <= T; jj++) {
    
    
                V[jj] = max(V[jj], A[1]);
            }
        }
        int ans = 0;
        int end = 0;
        int furthest = 0;
        for(int ii = 0; ii < T; ii++) {
    
    
            furthest = max(furthest, V[ii]);
            if(furthest == ii) return -1;
            if(ii == end) {
    
    
                ans++;
                end = furthest;
            }
        }
        return ans;
    }
};

猜你喜欢

转载自blog.csdn.net/m0_37454852/article/details/113849416