-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path523.cpp
More file actions
28 lines (28 loc) · 749 Bytes
/
Copy path523.cpp
File metadata and controls
28 lines (28 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution {
public:
bool checkSubarraySum(vector<int> &nums, int k) {
int n = nums.size();
if (k == 0) {
for (int i = 1; i < n; ++i) {
int sum = nums[i];
for (int j = i - 1; j >= 0; --j) {
sum += nums[j];
if (sum == 0)
return true;
}
}
return false;
}
if (n == 0)
return false;
for (int i = 1; i < n; ++i) {
int sum = nums[i];
for (int j = i - 1; j >= 0; --j) {
sum += nums[j];
if (sum % k == 0)
return true;
}
}
return false;
}
};