707. Sum of Array Elements Using Recursion

EasyRecursionRecursion

Given an integer array nums, return the sum of all its elements. You must compute the sum recursively, without using loops.

Input: An integer array nums.

Output: Return an integer equal to the sum of all elements.

Examples

Example 1
Input: [1,2,3,4,5]
Output: 15
Explanation: 1+2+3+4+5 = 15.
Example 2
Input: [-1,-2,-3]
Output: -6
Explanation: Sum of negatives is negative.
Example 3
Input: [7]
Output: 7
Explanation: Single element.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →