classSolution{public:boolcontainsPattern(vector<int>& arr,int m,int k){int N = arr.size();for(int i =0; i + k * m <= N; i++){bool flag =true;for(int j = i; j < i + k * m; j++){if(arr[j]!= arr[i +(j-i)% m]){
flag =false;break;}}if(flag)returntrue;}returnfalse;}};
2. 乘积为正数的最长子数组长度
classSolution{public:intgetMaxLen(vector<int>& nums){int N = nums.size();
vector<int>f(N),g(N);if(nums[0]>0)
f[0]=1;elseif(nums[0]<0)
g[0]=1;int res = f[0];for(int i =1; i < N; i++){if(nums[i]>0){
f[i]= f[i-1]+1;if(g[i-1])
g[i]= g[i-1]+1;}elseif(nums[i]<0){
g[i]= f[i-1]+1;if(g[i-1])
f[i]= g[i-1]+1;}
res =max(res,f[i]);}return res;}};
1.重复至少k次且长度为M的模式class Solution {public: bool containsPattern(vector<int>& arr, int m, int k) { int N = arr.size(); for(int i = 0; i + k * m <= N; i++) { bool flag = true; for(int j = i; j