Skip to content

Instantly share code, notes, and snippets.

@201power
Created April 15, 2014 06:53
Show Gist options
  • Save 201power/10708508 to your computer and use it in GitHub Desktop.
Save 201power/10708508 to your computer and use it in GitHub Desktop.
class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
int i,inc=0;
digits.back()=digits.back()+1;
if (digits.back() > 9){
inc=1;
digits.back()=digits.back()-10;
i=digits.size()-2;
while (i>=0) {
digits[i]=digits[i]+inc;
if (digits[i]>9){
digits[i]=digits[i]-10;
i--;
}
else{
inc=0;
break;
}
}
}
if (inc==1)
digits.insert(digits.begin(),1);
return digits;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment