If exceeding the "int" limit, how to solve it?

  • 0

    Input: {9}, {1,9,9,9,9,9,9,9,9,9}
    Output: {8,0,4,5,6,0,0,1,4,1}
    Expected: {0,0,0,0,0,0,0,0,0,0,1}

  • 4

    It will never exceed the limit, since you are not supposed to convert the numbers to ints in their entirety. The largest a number will get at any time is 19. The numbers in the example are 9 and 9999999991, which would be bigger than int, but you are only supposed to add 1+9 repeatedly, until you reach the end. Converting to int sidesteps the entire purpose of the problem.

    If you mean "the sum is greater than or equal to 10," then you take the ones digit and store it in the array, and add 1 to the next sum.

  • 0

    Try long long. But it's better to add the values one by one.

Log in to reply

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