Clicky

Leetcode 1480. Running Sum of 1d Array

January 3, 2020

1480. Running Sum of 1d Array)

Result

Runtime: 1411 ms, faster than 5.00% of Java online submissions for Container With Most Water. Memory Usage: 62.6 MB, less than 33.47% of Java online submissions for Container With Most Water.

class Solution {
    public int[] runningSum(int[] nums) {
        int[] result = new int[nums.length];
        for(int i=0; i<nums.length; i++) {
            if(i==0) {
                result[i] = nums[i];
                continue;
            }
            result[i] = result[i-1] + nums[i];
        }
        return result;
    }
}