FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/multiply-strings.py at master · pythonpeixun/LeetCode-Solutions · GitHub
pythonpeixun
/
LeetCode-Solutions
Public
forked from
kamyu104/LeetCode-Solutions
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
multiply-strings.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (32 loc) · 917 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
multiply-strings.py
Copy path
File metadata and controls
38 lines (32 loc) · 917 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# Time: O(m * n)
# Space: O(m + n)
class
Solution
(
object
):
def
multiply
(
self
,
num1
,
num2
):
"""
:type num1: str
:type num2: str
:rtype: str
"""
num1
,
num2
=
num1
[::
-
1
],
num2
[::
-
1
]
res
=
[
0
]
*
(
len
(
num1
)
+
len
(
num2
))
for
i
in
xrange
(
len
(
num1
)):
for
j
in
xrange
(
len
(
num2
)):
res
[
i
+
j
]
+=
int
(
num1
[
i
])
*
int
(
num2
[
j
])
res
[
i
+
j
+
1
]
+=
res
[
i
+
j
]
/
10
res
[
i
+
j
]
%=
10
# Skip leading 0s.
i
=
len
(
res
)
-
1
while
i
>
0
and
res
[
i
]
==
0
:
i
-=
1
return
''
.
join
(
map
(
str
,
res
[
i
::
-
1
]))
# Time: O(m * n)
# Space: O(m + n)
# Using built-in bignum solution.
class
Solution2
(
object
):
def
multiply
(
self
,
num1
,
num2
):
"""
:type num1: str
:type num2: str
:rtype: str
"""
return
str
(
int
(
num1
)
*
int
(
num2
))
Back
|
FazBrowse Home
|
New Git URL