Very Easy Solution with C++:


  • 0
    D
    class Solution {
    public:
        vector<int> plusOne(vector<int>& digits) {
            int c=1,i,j;
            vector<int>v;
            for(i=digits.size()-1;i>=0;i--)
            {
                int r=c+digits[i];
                c=r/10;
                r=r%10;
                v.push_back(r);
            }
            if(c==1)
                v.push_back(c);
            reverse(v.begin(),v.end());
            return v;
            
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.