Posted on

Description

Submission

class Solution {
public:
    bool canChoose(vector<vector<int>>& groups, vector<int>& nums) {
        int i = 0, k = 0;
        while(k < groups.size() && i < nums.size()) {
            auto& g = groups[k];
            int j = 0;
            for(; j < g.size(); ++j) {
                if(nums[i+j] != g[j]) break;
            }
            if(j == g.size()) {
                ++k;
                i += j;
            }
            else ++i;
        }

        if(k == groups.size()) return true;
        return false;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *