Array Sum - aloalgo

Array Sum

Easy

You are given an array of integers nums.

Your task is to return the sum of all the numbers in the array.

You may assume that:

  • nums can be empty, in which case the sum is 0.
  • Each element in nums is an integer that can be negative, zero, or positive.

Example 1

Input
[1, 2, 3, 4, 5]
Output
15
Explanation:

The sum of all elements is 1 + 2 + 3 + 4 + 5 = 15.

Example 2

Input
[10, -3, 7]
Output
14
Explanation:

The sum is 10 + (-3) + 7 = 14.

Example 3

Input
[]
Output
0
Explanation:

An empty array has a sum of 0.

Loading...
Input
[1, 2, 3, 4, 5]
Output
15

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!