Problema
Build a running sum: the value at position i is the sum of all numbers from position 0 through i.
Implement running_sum(numbers).
Input
numbers: The list of integers.
Output
Return the list of running totals.
Vincoli
0 ≤ length ≤ 100,000; totals fit in a 64-bit integer
Esempi
Esempio 1
Input:
numbers = [1, 2, 3, 4]
Output atteso:
expected = [1, 3, 6, 10]
Input:
std::vector<long long> numbers = {1, 2, 3, 4};
Output atteso:
std::vector<long long> expected = {1, 3, 6, 10};
Input:
long[] numbers = new long[] {1, 2, 3, 4};
Output atteso:
long[] expected = new long[] {1, 3, 6, 10};
Spiegazione
Totals so far: 1, 1+2=3, 3+3=6, 6+4=10.
Esempio 2
Input:
numbers = [5, -5, 5]
Output atteso:
expected = [5, 0, 5]
Input:
std::vector<long long> numbers = {5, -5, 5};
Output atteso:
std::vector<long long> expected = {5, 0, 5};
Input:
long[] numbers = new long[] {5, -5, 5};
Output atteso:
long[] expected = new long[] {5, 0, 5};
Spiegazione
Totals: 5, 0, 5.
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.