Indeed Python doesn't have an overflow problem

  • 0

    It's silly that this question insists on overflow for python solution. Python implements arbitrary precision and doesn't have the overflow problem.
    Here is a post to explain why:

    To mock the overflow I have to do the following in my code. It's sick to fake the overflow in python

        num = str[i:j]
        val = 0
        weight = 1
        for c in num[::-1]:
            val += int(c) * weight
            weight *= 10
            # there is no limit on python long type. mock the overflow here
            if not negative and val > 2147483647:
                val = 2147483647
            elif negative and val > 2147483648:
                val = 2147483648

Log in to reply

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