Problème
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.
Contraintes
0 ≤ length ≤ 100,000; totals fit in a 64-bit integer
Exemples
Exemple 1
Entrée :
numbers = [1, 2, 3, 4]
Sortie attendue :
expected = [1, 3, 6, 10]
Entrée :
std::vector<long long> numbers = {1, 2, 3, 4};
Sortie attendue :
std::vector<long long> expected = {1, 3, 6, 10};
Entrée :
long[] numbers = new long[] {1, 2, 3, 4};
Sortie attendue :
long[] expected = new long[] {1, 3, 6, 10};
Explication
Totals so far: 1, 1+2=3, 3+3=6, 6+4=10.
Exemple 2
Entrée :
numbers = [5, -5, 5]
Sortie attendue :
expected = [5, 0, 5]
Entrée :
std::vector<long long> numbers = {5, -5, 5};
Sortie attendue :
std::vector<long long> expected = {5, 0, 5};
Entrée :
long[] numbers = new long[] {5, -5, 5};
Sortie attendue :
long[] expected = new long[] {5, 0, 5};
Explication
Totals: 5, 0, 5.
Références
Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.