leetcode_question_66 Plus One
Given a number represented as an array of digits, plus one to the number.vector<int> plusOne(vector<int> &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function int length = digits.size(); if(length==0) return digits; bool carry = true; int index = length-1; while(carry && index >= 0) { digits[index] += carry; if(digits[index] > 9) {digits[index] = 0;carry = true;index--;} else {carry = false; break;} }; if(carry) digits.insert(digits.begin(), 1); return digits; }
补充:软件开发 , C++ ,