Indeed Python doesn't have an overflow problem


  • 0
    K

    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:
    http://mortada.net/can-integer-operations-overflow-in-python.html

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

        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
                break
            elif negative and val > 2147483648:
                val = 2147483648
                break

Log in to reply
 

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