Loading...
No output yet. Run your code to see results.
Sum of Array
#043
easy
array
algorithm
easy
Description
Write a function that calculates the sum of all numbers in an array.
Example:
-
Input:
nums = [1, 2, 3, 4, 5] -
Output:
15 -
Input:
nums = [-1, 0, 1] -
Output:
0
Instructions
- Return the sum of all elements
- Handle negative numbers correctly
- Return 0 for empty arrays