Very Simple Solution in JAVA


  • 0
    D
    class Solution
    {
        public int[] plusOne(int[] digits)
        {
        	int carry = 1;
        	for(int i = digits.length-1 ; i>=0; i--)
        	{
        		int temp = digits[i]+carry;
        		digits[i] = temp%10;
        		carry = temp/10;
        	}
        	
        	if(carry > 0)
        	{
        		int result[] = new int[digits.length+1];
        		result[0]=carry;
        		for(int i=1;i<result.length;i++)
        		{
        			result[i] = digits[i-1];
        		}
        		return result;
        	}
        	return digits;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.