[刷题班] LeetCode1480. 一维数组的动态和
题目描述
思路:前缀和
前缀和数组(prefixSum)的构造
方法一:
class Solution {
public int[] runningSum(int[] nums) {
int[] preSum = new int[nums.length];
preSum[0] = nums[0];
for (int i = 1; i < nums.length; i ++) {
preSum[i] = preSum[i - 1] + nums[i];
}
return preSum;
}
}