1
# Runtime: 69 ms (Top 20.00%) | Memory: 13.9 MB (Top 79.88%)6
def assign_sign(self, sign):7
# verify that we haven't already got a sign8
# "+42-" -> we don't want to return -42; hence check9
if not self.is_neg and not self.is_pos:10
# no sign has been set yet17
def add_to_int(self, num):21
self.num = (self.num * 10) + num23
def myAtoi(self, s: str) -> int:24
# remove the leading and trailing spaces30
# ignore the rest of the string if a non digit character is read32
# only read the first symbol; break if second symbol is read33
if self.is_pos or self.is_neg or isinstance(self.num, int):34
# one of the two symbols is read or a number is read42
# it's neither a sign, nor a number; terminate45
# outside the loop; compile the result48
upper_limit = 2**31 - 149
if self.is_pos or (not self.is_pos and not self.is_neg):50
if self.num > upper_limit:51
self.num = upper_limit53
if self.num > upper_limit + 1:54
self.num = upper_limit + 155
self.num = -1 * self.num