leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

3034.cpp (614B)


      1 class Solution {
      2   public:
      3     int countMatchingSubarrays(const vector<int> &nums, const vector<int> &pattern) const {
      4         const int n = size(nums), m = size(pattern);
      5         int res = 0;
      6 
      7         for (int i = 1; i <= n - m; i++) {
      8             for (int j = 0; j < m; j++) {
      9                 if (pattern[j] == -1 && nums[i + j] >= nums[i + j - 1]) goto next;
     10                 if (pattern[j] == 0 && nums[i + j] != nums[i + j - 1]) goto next;
     11                 if (pattern[j] == 1 && nums[i + j] <= nums[i + j - 1]) goto next;
     12             }
     13             res++;
     14         next:;
     15         }
     16 
     17         return res;
     18     }
     19 };