Skip to content

Instantly share code, notes, and snippets.

@ceth-x86
Created January 10, 2021 06:55
Show Gist options
  • Save ceth-x86/3d58e7ca343ef4a6795d732738080e7a to your computer and use it in GitHub Desktop.
Save ceth-x86/3d58e7ca343ef4a6795d732738080e7a to your computer and use it in GitHub Desktop.
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
bool next_step = true;
int pos = digits.size() - 1;
while (next_step && (pos >= 0)) {
digits[pos] += 1;
if (digits[pos] == 10) {
digits[pos] = 0;
next_step = true;
} else {
next_step = false;
}
pos -= 1;
}
if (next_step) {
digits.insert(digits.begin(), 1);
}
return digits;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment