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.
Subscribe to see which companies asked this question
vector<int> plusOne(vector<int>& digits) { int add = 1; int size = digits.size(); while (size-- && add > 0) { int num = digits[size] + add; add = num / 10; digits[size] = num % 10; } if (add > 0) digits.insert(digits.begin(), add); return digits; }