주어진 배열의 합계를 구하는 알고리즘을 작성해봤다!
public static int arraySum(int[] array) {
return arraySumRecur(array, array.length);
}
public static int arraySumRecur(int[] array, int idx) {
if (idx <= 0) {
return 0;
} else {
return arraySumRecur(array, idx - 1) + array[idx - 1];
}
}
'알고리즘 & 기능' 카테고리의 다른 글
| Fractal 연습해보기! (0) | 2020.11.04 |
|---|---|
| Math.pow() 함수 직접 구현해보기! (0) | 2020.11.04 |