Problema
Mostra originale (inglese)Restituisci il totale di tutti i numeri nella lista. Una lista vuota ha somma pari a 0.
Implementa sum_array(numbers).
Input
numbers: La lista di interi.
Output
Restituisci la somma.
Vincoli
0 ≤ lunghezza ≤ 100.000; il totale rientra in un intero a 64 bit
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
Niente da sommare: 0.
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.