MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / helper

Method helper

java/0930-binary-subarrays-with-sum.java:5–21  ·  view source on GitHub ↗
(int[] nums, int goal)

Source from the content-addressed store, hash-verified

3 return helper(nums, goal) - helper(nums, goal - 1);
4 }
5 private int helper(int[] nums, int goal){
6 if(goal < 0)
7 return 0;
8
9 int res = 0, sum = 0;
10 int l = 0;
11
12 for(int r = 0; r < nums.length; r++){
13 sum += nums[r];
14 while(sum > goal){
15 sum -= nums[l];
16 l += 1;
17 }
18 res += (r - l + 1);
19 }
20 return res;
21 }
22}

Callers 1

numSubarraysWithSumMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected