题目描述
思路:前缀和
前缀和数组(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;
}
}
标签:数组,nums,int,length,一维,LeetCode1480,preSum,刷题
From: https://www.cnblogs.com/keyongkang/p/17963849