Old Wei wins the offer to take you to learn --- Brush title series (49 to convert a string to an integer)

49. The string into an integer

problem:

Converting a string to an integer, the request can not use the library function converts the integer string. Value of 0 or a character string is not a valid return value 0

solve:

thought:

It is to be noted about the channel, 32-bit integer in the range of -2 31 to 2 * 32-1 *.

python code:

# -*- coding:utf-8 -*-
class Solution:
    def StrToInt(self, s):
        try:
            a=int(s)
            if(a<-(2**31) or a>(2**31-1)):
                return 0
            return a
        except Exception as e:
            return 0
Published 160 original articles · won praise 30 · views 70000 +

Guess you like

Origin blog.csdn.net/yixieling4397/article/details/105069254