Plus One Java Solution - The Coding Shala
Home >> Interview Questions >> Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.
Explanation: The array represents the integer 123.
Explanation: The array represents the integer 4321.
Plus One Java Solution
Here the simple idea is if the number in the array is less than 9 then we don't have to forward carry 1 to the next number.
if all the numbers are 9 in the array then we have to add 1 at the beginning of the array[need to create new array].
Other Posts You May Like