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) {
int size = digits.size();
int loc = size -1;
int added = 1;
while(added&&loc>=0){
if(digits[loc]<9){
digits[loc] += added;
added = 0;
}else{
digits[loc] = 0;
loc--;
}
}
if(added){
digits.insert(digits.begin(),added);
}
return digits;
}
};