Share my C# solution


  • 0
    D
    if (digits[digits.Length - 1] < 9)
            {
                digits[digits.Length - 1] = digits[digits.Length - 1] + 1;
                return digits;
            }
            else
            {
                ArrayList list = new ArrayList();
                int add = 1;
                for (int i = digits.Length - 1; i >= 0;--i)
                {
                    if (digits[i] == 9)
                    {
                        int insert = (digits[i] + add)%10;
                        list.Insert(0,insert);
                    }
                    else
                    {
                        add = digits[i] + add;
                        list.Insert(0, add);
                        add = 0;
                    }
                }
                if (Convert.ToInt32(list[0]) == 0)
                {
                    list.Insert(0, 1);
                }
                int[] result = list.ToArray(typeof(int)) as int[];
                return result;
            }

Log in to reply
 

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