Skip to content

Commit 842117b

Browse files
committed
Runtime: 69 ms (Top 20.00%) | Memory: 13.9 MB (Top 79.88%)
1 parent 8394bac commit 842117b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scripts/algorithms/S/String to Integer (atoi)/String to Integer (atoi).py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
# Runtime: 69 ms (Top 20.00%) | Memory: 13.9 MB (Top 79.88%)
2+
13
class Solution:
2-
4+
35
def assign_sign(self, sign):
46
# verify that we haven't already got a sign
57
# "+42-" -> we don't want to return -42; hence check
@@ -10,13 +12,13 @@ def assign_sign(self, sign):
1012
elif sign=="-":
1113
self.is_neg = True
1214
return
13-
15+
1416
def add_to_int(self, num):
1517
if not self.num:
1618
self.num = num
1719
else:
1820
self.num = (self.num*10) + num
19-
21+
2022
def myAtoi(self, s: str) -> int:
2123
# remove the leading and trailing spaces
2224
self.is_neg = False
@@ -38,7 +40,7 @@ def myAtoi(self, s: str) -> int:
3840
except ValueError:
3941
# it's neither a sign, nor a number; terminate
4042
break
41-
43+
4244
# outside the loop; compile the result
4345
if not self.num:
4446
return 0
@@ -51,4 +53,3 @@ def myAtoi(self, s: str) -> int:
5153
self.num = upper_limit+1
5254
self.num = -1 * self.num
5355
return self.num
54-

0 commit comments

Comments
 (0)