-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
29 lines (28 loc) · 742 Bytes
/
Solution.cs
File metadata and controls
29 lines (28 loc) · 742 Bytes
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
public class Solution
{
public int MinimumSumSubarray(IList<int> nums, int l, int r)
{
int n = nums.Count;
int[] prefixSum = new int[nums.Count + 1];
for (int i = 0; i < n; i++)
{
prefixSum[i + 1] = prefixSum[i] + nums[i];
}
int ans = int.MaxValue;
for (int i = l; i <= n; i++)
{
for (int j = l; j <= r && i - j >= 0; j++)
{
int c = prefixSum[i] - prefixSum[i - j];
if (c > 0)
{
if (ans > c)
{
ans = c;
}
}
}
}
return ans == int.MaxValue ? -1 : ans;
}
}