Skip to content

Commit 7dd2cba

Browse files
committed
Add 523
1 parent 99c0faf commit 7dd2cba

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
bool checkSubarraySum(vector<int>& nums, int k) {
4+
bool flag = false;
5+
if(k==0)
6+
flag = true;
7+
vector<int> dp(nums.size(),0);
8+
for(int i=0;i<nums.size();i++){
9+
int sum = nums[i];
10+
for(int j=i+1;j<nums.size();j++){
11+
sum += nums[j];
12+
if(flag){
13+
if(sum - k == 0)
14+
return true;
15+
}
16+
else{
17+
if (sum % k == 0)
18+
return true;
19+
}
20+
}
21+
}
22+
return false;
23+
}
24+
};

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@
577577

578578
[506.Relative-Ranks](Algorithms/506.Relative-Ranks/solution.cpp)
579579

580+
[523.Continuous-Subarray-Sum](Algorithms/523.Continuous-Subarray-Sum/solution.cpp)
581+
580582
[645.Set-Mismatch](Algorithms/645.Set-Mismatch/solution.cpp)
581583

582584
[674.Longest-Continuous-Increasing-Subsequence](Algorithms/674.Longest-Continuous-Increasing-Subsequence/solution.cpp)

0 commit comments

Comments
 (0)