Tutte le sfide
Facile 0 risolte 0% di accettazione

Sum an Array

Add up all values in a list.

Return the total of all numbers in the list. An empty list sums to 0.

Implement sum_array(numbers).

Input

numbers: The list of integers.

Output

Return the sum.

Vincoli

0 ≤ length ≤ 100,000; the total fits in a 64-bit integer

Esempi

Esempio 1
Input:
numbers = [1, 2, 3, 4]

Output atteso:
expected = 10
Input:
std::vector<long long> numbers = {1, 2, 3, 4};

Output atteso:
long long expected = 10;
Input:
long[] numbers = new long[] {1, 2, 3, 4};

Output atteso:
long expected = 10;

Spiegazione

1 + 2 + 3 + 4 = 10.

Esempio 2
Input:
numbers = []

Output atteso:
expected = 0
Input:
std::vector<long long> numbers = {};

Output atteso:
long long expected = 0;
Input:
long[] numbers = new long[] {};

Output atteso:
long expected = 0;

Spiegazione

Nothing to add: 0.

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.