Array Sum
Easy · rating 850 · arrays, math
The first line contains n. The second line contains n space-separated integers. Print their sum.
Constraints: 1 ≤ n ≤ 105, |ai| ≤ 109
Editorial
Array Sum totals all the integers in a list. Accumulate in a single pass, and keep the total in a 64-bit integer since many large values can overflow 32 bits.
print(sum(nums))Complexity
Time: O(n). Space: O(1).