GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — algorithms/string/multiply_strings.py at master · vspriya05/algorithms Expand file tree/ Copy pathmultiply_strings.pyMore file actions 36 lines (30 loc) · 913 Bytes / Copy pathmultiply_strings.pyFile metadata and controls36 lines (30 loc) · 913 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 """ Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2. Note: The length of both num1 and num2 is < 110. Both num1 and num2 contains only digits 0-9. Both num1 and num2 does not contain any leading zero. You must not use any built-in BigInteger library or convert the inputs to integer directly. """ def multiply(num1:"str", num2:"str")->"str": carry = 1 interm = [] zero = ord('0') i_pos = 1 for i in reversed(num1): j_pos = 1 add = 0 for j in reversed(num2): mult = (ord(i)-zero) * (ord(j)-zero) * j_pos * i_pos j_pos *= 10 add += mult i_pos *= 10 interm.append(add) return str(sum(interm)) if __name__ == "__main__": print(multiply("1", "23")) print(multiply("23", "23")) print(multiply("100", "23")) print(multiply("100", "10000")) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |