Skip to content

Commit 189c706

Browse files
committed
algorithms/src/main/java/ivanmarkovic/algorithms/recursion/SumNumbersInArrayBinaryRecursion.java
1 parent 3194f89 commit 189c706

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+
package ivanmarkovic.algorithms.recursion;
2+
3+
public class SumNumbersInArrayBinaryRecursion {
4+
5+
6+
public static int sumNumbers(int nums[]) {
7+
return helper(nums, 0, nums.length - 1);
8+
}
9+
10+
private static int helper(int[] nums, int start, int end) {
11+
if(start > end)
12+
return 0;
13+
else {
14+
int index = start + (end - start) / 2;
15+
return helper(nums, start, index - 1) + nums[index] + helper(nums, index + 1, end);
16+
}
17+
}
18+
19+
20+
21+
}

0 commit comments

Comments
 (0)