首页 > 代码库 > Plus One

Plus One

Given a non-negative number represented as an array of digits, plus one to the number.

The digits are stored such that the most significant digit is at the head of the list.

class Solution {public:    vector<int> plusOne(vector<int> &digits) {        vector<int>::reverse_iterator r_iter=digits.rbegin();        while(*r_iter==9){            *r_iter=0;            r_iter++;            if(r_iter==digits.rend()){                digits.insert(digits.begin(),1);                return digits;            }                        }        (*r_iter)++;        return digits;    }};

 

Plus One