Leetcode high precision Plus One, leetcodeplus
This article is senlie original, reproduced Please retain this address: http://blog.csdn.net/zhengsenlie
Plus One Total Accepted: 17614 Total Submissions: 55852My Submissions
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
Given an array that represents a large integer, each element of the array adds 1 to each digit in decimal notation of the expected number.
Idea: high-precision Addition
Complexity: Time: O (n)
vector<int> plusOne(vector<int> &digits){int carry = 1;for(auto it = digits.rbegin(); it != digits.rend(); ++it){int tmp = *it + carry;*it = tmp % 10;carry = tmp / 10;if(!carry) break;}if(carry) digits.insert(digits.begin(), carry);return digits;}
I think one plus one equals two is wrong. Isn't it true that a sentence can only have one verb? There are two verbs.
Hello, plus is a prefix, indicating that
Minus Subtraction is also a prefix.
What is plus one?
(Plus [pl ʌ s] n. Positive, plus sign; additional amount; Benefit
Adj. Positive; appended
Prep. Add
Plus one golf match strong to the weak) Let a point, let a blow