-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path66-Plus-One.cpp
More file actions
34 lines (29 loc) · 1.01 KB
/
66-Plus-One.cpp
File metadata and controls
34 lines (29 loc) · 1.01 KB
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
31
32
33
34
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
for(int i = digits.size()-1; i >= 0; --i){
if (digits[i] < 9){
digits[i]++;
return digits;
}
else{
digits[i] = 0;
}
}
digits[0] = 1;
digits.push_back(0);
return digits;
}
};
/* 66. Plus-One.cpp
//////////////////////////////////////////////////
Given a non-empty array of decimal digits representing a non-negative integer, increment one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contains a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.
Input: digits = [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.
temp += digits[(digits.size()-1)-i]*pow(10.0, i);
https://leetcode.com/problems/plus-one/
//////////////////////////////////////////////////
*/