Easy
Calculate the Sum of Array Elements
- Time limit
- 1 s
- Memory limit
- 128 MB
- Estimated
- 15 min
- Arrays and Strings
Description
Given an array of integers, calculate and return the sum of all its elements.
Every element must contribute exactly once to the total. The array may contain positive numbers, negative numbers, and zero.
For example, the sum of [1, 2, 3, 4] is 10.
Implement sumArray(nums) to return the sum of the elements.
Constraints
1 <= nums.length <= 1000 -1000000 <= nums[i] <= 1000000 The absolute sum of all elements does not exceed 1000000000.
Sample cases
3Sample 1
Input
nums = [1,2,3,4]
Expected output
10
Sample 2
Input
nums = [-5,5]
Expected output
0
Skills and languages
Concepts
- Control Flow and Data Types
Languages
- Python 3
Solve this problem
Create a free account to write, run and submit your solution.
- Write Python or Java in the browser, with your draft saved as you type
- Run your code on the examples as often as you like
- Submit to a sandboxed judge and see exactly which case failed
- Ask the AI mentor for a hint without being handed the answer