Judie 发表于 2023-5-23 11:40:30

【朱迪的LeetCode刷题笔记】1480. Running Sum of 1d Array #Easy #Python

本帖最后由 Judie 于 2023-5-23 02:22 编辑

Given an array nums. We define a running sum of an array as runningSum = sum(nums…nums).
Return the running sum of nums.

Example 1:
Input: nums =
Output:
Explanation: Running sum is obtained as follows: .

Example 2:
Input: nums =
Output:
Explanation: Running sum is obtained as follows: .

Example 3:
Input: nums =
Output:


Constraints:
1 <= nums.length <= 1000
-10^6 <= nums <= 10^6

class Solution(object):
    def runningSum(self, nums):
      """
      :type nums: List
      :rtype: List
      """

Judy
class Solution(object):
    def runningSum(self, nums):
      """
      :type nums: List
      :rtype: List
      """
      i = 1
      l = len(nums)
      s = nums
      runningSum =
      while i < l:
            s += nums
            runningSum.append(s)
            i +=1
      return runningSum
      


Gray
class Solution(object):
    def runningSum(self, nums):
      """
      :type nums: List
      :rtype: List
      """
      ans = []
      temp = 0
      for x in nums:
            ans.append(temp + x)
            temp = temp + x
      return ans

不二如是 发表于 2023-5-23 19:35:36

不错,希望更下去

Judie 发表于 2023-5-23 23:55:21

不二如是 发表于 2023-5-23 06:35
不错,希望更下去

谢谢 我努力!
页: [1]
查看完整版本: 【朱迪的LeetCode刷题笔记】1480. Running Sum of 1d Array #Easy #Python