Skip to content

Commit c7f51bc

Browse files
authored
Merge pull request #3213 from Dalton-V/main
Added 0523-continuous-subarray-sum.cs
2 parents 4fa91e4 + b2d50df commit c7f51bc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Solution
2+
{
3+
public bool CheckSubarraySum(int[] nums, int k)
4+
{
5+
var remainder = new Dictionary<int, int>();
6+
remainder.Add(0, -1);
7+
var total = 0;
8+
for (var i = 0; i < nums.Length; i++)
9+
{
10+
total += nums[i];
11+
var r = total % k;
12+
if (!remainder.ContainsKey(r))
13+
remainder.Add(r, i);
14+
else if (i - remainder[r] > 1)
15+
return true;
16+
}
17+
return false;
18+
}
19+
}

0 commit comments

Comments
 (0)