leetcode

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

0989.cpp (342B)


      1 class Solution {
      2   public:
      3     vector<int> addToArrayForm(vector<int> &num, int k) {
      4         vector<int> res;
      5 
      6         for (int i = num.size() - 1; i >= 0 || k; i--) {
      7             if (i >= 0) k += num[i];
      8             res.push_back(k % 10);
      9             k /= 10;
     10         }
     11 
     12         reverse(res.begin(), res.end());
     13         return res;
     14     }
     15 };