-
Notifications
You must be signed in to change notification settings - Fork 0
/
plusone_vec.cpp
30 lines (30 loc) · 905 Bytes
/
plusone_vec.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <vector>
#include <stdlib.h>
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
int tmp = 0;
for(auto it=digits.end()-1; it>=digits.begin(); it--){
if(it==digits.end()-1){
*it+=1;
if(*it>=10){
*it-=10;
tmp=1;
}
continue;
}
*it+=tmp;
if(*it>=10){
tmp = 1;
*it-=10;
}
else
tmp = 0;
}
if(tmp ==1){
digits.insert(digits.begin(), tmp, 1);
}
return digits;
}
};