zoukankan      html  css  js  c++  java
  • 1480. 一维数组的动态和

    地址:https://leetcode-cn.com/problems/running-sum-of-1d-array/

    <?php
    /**
    给你一个数组 nums 。数组「动态和」的计算公式为:runningSum[i] = sum(nums[0]…nums[i]) 。
    
    请返回 nums 的动态和。
    
     
    
    示例 1:
    
    输入:nums = [1,2,3,4]
    输出:[1,3,6,10]
    解释:动态和计算过程为 [1, 1+2, 1+2+3, 1+2+3+4] 。
    示例 2:
    
    输入:nums = [1,1,1,1,1]
    输出:[1,2,3,4,5]
    解释:动态和计算过程为 [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1] 。
    示例 3:
    
    输入:nums = [3,1,2,10,1]
    输出:[3,4,6,16,17]
     
    
    提示:
    
    1 <= nums.length <= 1000
    -10^6 <= nums[i] <= 10^6
    
    来源:力扣(LeetCode)
    链接:https://leetcode-cn.com/problems/running-sum-of-1d-array
    著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
     */
    class Solution {
    
        /**
         * @param Integer[] $nums
         * @return Integer[]
         */
        function runningSum($nums) {
            $num = $nums[0];
    
            for ($i = 1, $count = count($nums); $i < $count; $i++) {
                $nums[$i] = $num += $nums[$i];
            }
    
            return $nums;
        }
    }
  • 相关阅读:
    Hashmap实现原理
    策略模式
    Google Drive ubuntu
    numix Docky
    Google Drive 和 Dropbox 同步同一个文件夹目录
    sublime text 2
    matlab cell
    liteide
    taglist and nerdtree
    codeblocks
  • 原文地址:https://www.cnblogs.com/8013-cmf/p/13203957.html
Copyright © 2011-2022 走看看