1480. Running Sum of 1d Array

Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).

Return the running sum of nums.

求数组的前缀和

class Solution(object):
    def runningSum(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        for i in range(1, len(nums), 1):
            nums[i] += nums[i - 1]
        return nums

 

posted @ 2020-06-28 20:44  whatyouthink  阅读(88)  评论(0编辑  收藏  举报