-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiplication of string number representations without string to int conversions explicitly
- Loading branch information
1 parent
b0bcc23
commit fedd5a4
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Solution: | ||
def multiply(self, num1: str, num2: str) -> str: | ||
total = 0 | ||
for i,digit in enumerate(num1[::-1]): | ||
for j, digit2 in enumerate(num2[::-1]): | ||
total += (self.chtoi(digit) * (10 ** i)) * (self.chtoi(digit2) * (10 ** j)) | ||
return str(total) | ||
|
||
def chtoi(self, ch: str) -> int: | ||
if ch == "0": | ||
return 0 | ||
elif ch == "1": | ||
return 1 | ||
elif ch == "2": | ||
return 2 | ||
elif ch == "3": | ||
return 3 | ||
elif ch == "4": | ||
return 4 | ||
elif ch == "5": | ||
return 5 | ||
elif ch == "6": | ||
return 6 | ||
elif ch == "7": | ||
return 7 | ||
elif ch == "8": | ||
return 8 | ||
elif ch == "9": | ||
return 9 | ||
else: | ||
raise Error("bronkened") |