mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-17 16:51:46 +00:00
Initial commit
This commit is contained in:
18
Easy/plus-one/solution.cpp
Normal file
18
Easy/plus-one/solution.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <vector>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
std::vector<int> plusOne(std::vector<int> &digits) {
|
||||
++digits[digits.size() - 1];
|
||||
for (int i = digits.size() - 1; i >= 0 && digits[i] == 10; --i) {
|
||||
digits[i] = 0;
|
||||
if (i != 0) {
|
||||
++digits[i - 1];
|
||||
} else {
|
||||
digits.insert(digits.begin(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
return digits;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user