https://leetcode.com/problems/plus-one/description/
vector<int> plusOne(vector<int>& digits) {
int c = 1, t;
for(int i=digits.size()-1; i>=0 && c; i--) {
digits[i] += c;
c = digits[i]/10;
digits[i] %= 10;
}
if(c) digits.insert(digits.begin(), 1);
return digits;
}
No comments:
Post a Comment