leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1480.cpp (445B)


      1 class Solution {
      2   public:
      3     vector<int> runningSum(vector<int> &nums) {
      4         vector<int> res;
      5         int acc = 0;
      6         for (auto i : nums)
      7             res.push_back(acc += i);
      8         return res;
      9     }
     10 };
     11 
     12 // using lambda function
     13 class Solution {
     14   public:
     15     vector<int> runningSum(vector<int> &nums) {
     16         int acc = 0;
     17         for_each(nums.begin(), nums.end(), [&acc](int &a) { a = acc += a; });
     18         return nums;
     19     }
     20 };