We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 76908ed + 720c1e2 commit a9cde93Copy full SHA for a9cde93
523. Continuous Subarray Sum
@@ -0,0 +1,27 @@
1
+class Solution {
2
+public:
3
+ bool checkSubarraySum(vector<int>& nums, int k) {
4
+
5
+ int n = nums.size();
6
+ int sum = 0;
7
+ map<int,int>ma;
8
9
+ ma[0] = -1;
10
11
+ for(int i=0;i<n;i++){
12
+ sum+=nums[i];
13
14
+ if(ma.find(sum%k)!=ma.end()){
15
16
+ int foundAt = ma[sum%k];
17
+ if(i-foundAt>=2){
18
+ return true;
19
+ }
20
21
+ else{
22
+ ma[sum%k] = i;
23
24
25
+ return false;
26
27
+};
0 commit comments