点击打开链接
class Solution {
public:
bool checkSubarraySum(vector<int>& nums, int k) {
int sz = nums.size();
vector<int> sum(nums.begin(), nums.end());
for(int len=2; len<=sz; len++){
for(int i=0; i<=sz-len; i++){
sum[i] += nums[i+len-1];
if(sum[i]==0) return true;
else if(k!=0 && sum[i]%k ==0) return true;
}
}
return false;
}
};
![](https://i-blog.csdnimg.cn/blog_migrate/2a9db40ac4ef691496ecf8bda2f24cdf.png)