Untitled

mail@pastecode.io avatar
unknown
plain_text
22 days ago
557 B
1
Indexable
Never
class Solution {
public:
    int countMatchingSubarrays(vector<int>& nums, vector<int>& pat){
        int n=nums.size(), m=pat.size();
        int cnt=0;
        for(int i=0;i<n-m;i++){ 
            int k;
            for(k=0;k<m;k++){
                if(i+k+1 >=n) continue;
                if(pat[k]==1 && nums[i+k+1]<=nums[i+k]) break;
                else if(pat[k]==0 && nums[i+k+1]!=nums[i+k]) break;
                else if(pat[k]==-1 && nums[i+k+1] >=nums[i+k]) break;
            }
            if(k==m) cnt++;
        }
        return cnt;
    }
};
Leave a Comment