Given a non-negative number represented as an array of digits, plus one to the number.
The digits is stored such, the most significant digit was at the head of the list.
Test instructions: An integer is stored in a bitwise array of int, arranged in the order of the highest bit in digits[0], the lowest bit in digits[n-1],//for example: 98, stored as: digits[0]=9; digits[1]=8;//: Add 1 from the last digit of the array, consider rounding, and if there is still a carry present after the digits[0] bit, add the rounding to the class solution {public: Vector<int > PlusOne (vector<int> &digits) { //important:please Reset any member data you declared, as //The S Ame Solution instance'll be reused to each test case. int a = 1; Vector<int> ans; Vector<int>::iterator it; for (int i = digits.size ()-1;i >= 0;i--) { it = Ans.begin (); int tmp = (A + digits[i])%; A = (A + digits[i])/ten; Ans.insert (it, TMP); } if (A! = 0) { it = Ans.begin (); Ans.insert (it, a); } return ans; };
Leetcode 66:plus One