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