leetcode

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

0066.cpp (365B)


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