Skip to content

Commit 5c1544a

Browse files
authored
Create Solution.java
1 parent 5810c77 commit 5c1544a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int numSubarraysWithSum(int[] A, int S) {
3+
int[] map = new int[A.length + 1];
4+
map[0] = 1;
5+
int res = 0;
6+
int s = 0;
7+
for (int a : A) {
8+
s += a;
9+
if (s >= S) {
10+
res += map[s - S];
11+
}
12+
++map[s];
13+
}
14+
return res;
15+
}
16+
}

0 commit comments

Comments
 (0)