We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d44f5a6 commit e72973aCopy full SHA for e72973a
atoi.py
@@ -0,0 +1,19 @@
1
+# Convert the string "123" into 123, without using the built-api `int()`
2
+
3
+# Startegy
4
+# 1. loop through each digit
5
+# 2. find the digit in range object of range(10)
6
+# 3. once the number is found, add it in placeholder
7
+# 4. Multiply each iteration by 10 (start with 0)
8
9
+def atoi(inputStr):
10
+ outputNum = 0
11
+ for char in inputStr:
12
+ for i in range(10):
13
+ if str(i) == char:
14
+ outputNum = outputNum * 10 + i
15
+ return outputNum
16
17
+x = "123"
18
+y = atoi(x)
19
+print(y)
0 commit comments