반응형
    
    
    
  
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;
    }
};

반응형
    
    
    
  'IT > 알고리즘' 카테고리의 다른 글
| 6] Leetcode 771. Jewels and Stones (0) | 2020.06.21 | 
|---|---|
| 5] Leetcode 1342. Number of Steps to Reduce a Number to Zero (0) | 2020.06.21 | 
| 4] Leetcode 1108. Defanging an IP Address (0) | 2020.06.21 | 
| 3] Leetcode 1431. Kids With the Greatest Number of Candies (0) | 2020.06.18 | 
| 2] Leetcode 1470. Shuffle the Array (0) | 2020.06.16 | 
										
									
										
									
댓글