본문 바로가기
IT/알고리즘

1] Leetcode 1480. Running Sum of 1d Array

by 깻잎쌈 2020. 6. 16.
반응형

 

 

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:
    vector<int> runningSum(vector<int>& nums) {
        for(int i=1;i<nums.size();i++)
            nums[i] = nums[i]+nums[i-1];
        
        return nums;
    }
};

 

 

반응형

댓글