First, the topic
The large number that is saved with an array, each element represents a number of one, and the number is added 1 to the size of the change.
Second, analysis
See this one we'll think about when we're dealing with large numbers. The use of high-precision calculation methods, we need to pay attention to the following areas:
1. Start traversing from the last face of the array
2, the current number plus low carry
3. Carry the current bit to the high position
4, each time to get a carry judgment is 0, 0 can be directly ended, to a certain extent, speed up the efficiency of the algorithm.
5. The last one needs to be aware that if the highest bit has carry, you need to add an element to the front.
Class Solution {public: vector<int> plusone (vector<int> &digits) { int len = Digits.size (); int carry = 1; int flag; for (int i=len-1;i>=0;i--) { digits[i]+=carry; flag = digits[i]%10; carry = DIGITS[I]/10; Digits[i] = flag; if (!carry) break ; } if (carry) Digits.insert (Digits.begin (), carry); return digits;} ;
Leetcode:plus One