Skip to content

Commit e624ccb

Browse files
committed
Refactor: Simplify the code
1 parent 20c6c20 commit e624ccb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Python/string-to-integer-atoi.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ def myAtoi(self, str):
5050
sign = -1
5151
i += 1
5252

53-
while i < len(str) and str[i] >= '0' and str[i] <= '9':
54-
if result > (INT_MAX - (ord(str[i]) - ord('0'))) / 10:
53+
while i < len(str) and '0' <= str[i] <= '9':
54+
if result > (INT_MAX - int(str[i])) / 10:
5555
return INT_MAX if sign > 0 else INT_MIN
56-
result = result * 10 + ord(str[i]) - ord('0')
56+
result = result * 10 + int(str[i])
5757
i += 1
5858

5959
return sign * result

0 commit comments

Comments
 (0)