Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Created November 5, 2018 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpdjsns/9cd1133c760c32d2c2b2bef6ae0a3656 to your computer and use it in GitHub Desktop.
Save fpdjsns/9cd1133c760c32d2c2b2bef6ae0a3656 to your computer and use it in GitHub Desktop.
[leetcode] 66. Plus One : https://leetcode.com/problems/plus-one/
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
bool carry = true;
vector<int> ans(digits.size(), 0);
for(int i=digits.size()-1;i>=0;i--){
int sum = carry + digits[i];
carry = sum / 10;
ans[i] = sum % 10;
}
if(carry) ans.insert(ans.begin(), 1);
return ans;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment