#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param s string字符串 
# @return int整型
#
class Solution:
    def StrToInt(self , s: str) -> int:
        # write code here
        ans, s = 0, s.strip()
        if not s:
            return 0
        sign = -1 if s[0]=='-' else 1
        s = s[1:] if s[0]=='-' or s[0]=='+' else s[:]
        for c in s:
            if c.isdigit():
                ans *= 10
                ans += int(c)
            else:
                break
        return min(max(sign * ans, -2 ** 31), 2 ** 31 - 1)