classSolution: defmyAtoi(self, str: str) -> int: p = '' str = str.lstrip() n = '' min_int = -2**31 max_int = 2**31-1 isnumeric = False for x in str: ifnot isnumeric and x == '-': p = '-' isnumeric = True continue ifnot isnumeric and x == '+': isnumeric = True continue if x.isnumeric(): n += x isnumeric = True else: break ifnot n: return0 if int(n) > max_int: if p: return min_int else: return max_int p += n return int(p) # 32 ms 13.6 MB