mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
15 lines
379 B
C++
15 lines
379 B
C++
class Solution {
|
|
public:
|
|
vector<int> plusOne(vector<int>& digits) {
|
|
int carry = 1;
|
|
for(int i = digits.size() - 1; i >= 0; --i) {
|
|
int add = digits[i] + carry;
|
|
digits[i] = add % 10;
|
|
carry = add / 10;
|
|
}
|
|
if(carry > 0) {
|
|
digits.insert(digits.begin(), carry);
|
|
}
|
|
return digits;
|
|
}
|
|
}; |