-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08jun.txt
29 lines (26 loc) · 943 Bytes
/
08jun.txt
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
29
class Solution {
public:
bool checkSubarraySum(vector<int>& nums, int k) {
int n = nums.size();
// Step 1: Iterate Through Starting Points
for (int start = 0; start < n - 1; start++) {
// Step 2: Expand the Subarray
for (int end = start + 1; end < n; end++) {
// Step 3: Calculate the Sum
int subarraySum = 0;
for (int i = start; i <= end; i++) {
subarraySum += nums[i];
}
// Step 4: Check if the Sum is a Multiple of k
if (subarraySum == 0 && k == 0) { // Handling special case where k is 0
return true;
}
if (k != 0 && subarraySum % k == 0) {
return true;
}
}
}
// Step 5: Return the Result
return false;
}
};