Simple Array Sum
easy
Given an array of integers, compute the sum of all the elements in the array.
Example 1
Input
[ 1, 2, 3 ]
Output
6
Explanation. The sum of 1, 2, and 3 is 6.
Example 2
Input
[ -1, -2, -3, 1 ]
Output
-5
Explanation. The sum of -1, -2, -3, and 1 is -5.
Example 3
Input
[ 0, 0, 0, 0 ]
Output
0
Explanation. The sum of four zeros is 0.
Example 4
Input
[ 1000, -1000 ]
Output
0
Explanation. The sum of 1000 and -1000 is 0.
Follow-up: Can you optimize your solution to use the least amount of additional memory?
Constraints:
- The array will contain at least 1 and at most 1000 elements.\n- Each element in the array will be an integer between -1000 and 1000.