LeetCode_Study_Plan/LeetCode 75

1480. Running Sum of 1d Array java

개발하는루루 2022. 9. 25. 17:01

https://leetcode.com/problems/running-sum-of-1d-array/?envType=study-plan&id=level-1 

 

Running Sum of 1d Array - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

class Solution {
  public int[] runningSum(int[] nums) {

    Integer[] ans = new Integer[nums.length];

    ans[0] = nums[0];

    for (int i = 1; i < nums.length; i++){
      ans[i] =  nums[i] + ans[i-1];
    }

    for (int i = 1; i < nums.length; i++){
      nums[i] =  ans[i];
    }

    return nums;
  }
}