Đề bài
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.
Ràng buộc
0 ≤ length ≤ 100,000; totals fit in a 64-bit integer
Ví dụ
Ví dụ 1
Đầu vào:
numbers = [1, 2, 3, 4]
Kết quả mong đợi:
expected = [1, 3, 6, 10]
Đầu vào:
std::vector<long long> numbers = {1, 2, 3, 4};
Kết quả mong đợi:
std::vector<long long> expected = {1, 3, 6, 10};
Đầu vào:
long[] numbers = new long[] {1, 2, 3, 4};
Kết quả mong đợi:
long[] expected = new long[] {1, 3, 6, 10};
Giải thích
Totals so far: 1, 1+2=3, 3+3=6, 6+4=10.
Ví dụ 2
Đầu vào:
numbers = [5, -5, 5]
Kết quả mong đợi:
expected = [5, 0, 5]
Đầu vào:
std::vector<long long> numbers = {5, -5, 5};
Kết quả mong đợi:
std::vector<long long> expected = {5, 0, 5};
Đầu vào:
long[] numbers = new long[] {5, -5, 5};
Kết quả mong đợi:
long[] expected = new long[] {5, 0, 5};
Giải thích
Totals: 5, 0, 5.
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.