Given an integer array nums, return an array ans of the same length where each element ans[i] equals the sum of nums[0] through nums[i] (inclusive). This is the running prefix sum of nums.
Constraints:
Input: nums = [1, 2, 3, 4]-List[int]
Output: [1, 3, 6, 10]-List[int]
Explanation: ans[0] = 1, ans[1] = 1 + 2 = 3, ans[2] = 1 + 2 + 3 = 6, and ans[3] = 1 + 2 + 3 + 4 = 10.
Input: nums = [1, 1, 1, 1, 1]-List[int]
Output: [1, 2, 3, 4, 5]-List[int]
Explanation: Each position adds the next 1 to the running total.
Input: nums = [3, 1, 2, 10, 1]-List[int]
Output: [3, 4, 6, 16, 17]-List[int]
Explanation: Tracking a cumulative sum while scanning left to right gives 3 → 4 → 6 → 16 → 17.
Input: nums = [-2, 0, 3, -5]-List[int]
Output: [-2, -2, 1, -4]-List[int]
Explanation: Running sums can decrease when encountering negative numbers: -2, then -2 + 0 = -2, then -2 + 0 + 3 = 1, then -2 + 0 + 3 - 5 = -4.
Input: nums = [7]-List[int]
Output: [7]-List[int]
Explanation: With one element, the running sum array is the same as the input.
Now, let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem: