Posted on 2023-02-15 19:16
Uriel 阅读(28)
评论(0) 编辑 收藏 引用 所属分类:
闲来无事重切Leet Code 、
大水题
模拟大数相加,水题~
1 #989
2 #Runtime: 242 ms (Beats 85.81%)
3 #Memory: 14.3 MB (Beats 28.38%)
4
5 class Solution(object):
6 def addToArrayForm(self, num, k):
7 """
8 :type num: List[int]
9 :type k: int
10 :rtype: List[int]
11 """
12 num2 = []
13 while k > 0:
14 num2.append(k % 10)
15 k = k // 10
16 num = num[::-1]
17 t = 0
18 s = []
19 for i in range(0, max(len(num), len(num2))):
20 if i < len(num):
21 t += num[i]
22 if i < len(num2):
23 t += num2[i]
24 s.append(t % 10)
25 t = t // 10
26 while t:
27 s.append(t % 10)
28 t = t // 10
29 return s[::-1]