Skip to content

Commit 796f7cb

Browse files
committed
Added 0523-continuous-subarray-sum.cs
1 parent f5a9f86 commit 796f7cb

File tree

1 file changed

+21
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)