TVP

# 大整数加法

832. 统计负数

Given mat =

return.

count =

depth =len(nums)

width =len(nums[])

foriinrange(depth):

ifnums[i][]

forjinrange(width):

ifnums[i][j]

count+=1

729. 阶乘除法的最后一位数

factor=1

value = B

whilevalue> A:

factor=((value%10)*factor)%10

ifint(factor)==:

returnint(factor)

value-=1

returnint(factor)

655. 大整数加法

num1 和 num2 的长度都小于5100。

num1 和 num2 都只包含数字 0-9。

num1 和 num2 都不包含任何前导零。

resultstr = []

numlist1 =list(num1)

numlist2 =list(num2)

length1 =len(numlist1)

length2 =len(numlist2)

iflength1 > length2:

minlength = length2

else:

minlength = length1

numlist1.reverse()

numlist2.reverse()

promotion =

foriinrange(,minlength):

ifint(numlist1[i]) +int(numlist2[i]) + promotion

resultstr.append(str(int(numlist1[i]) +int(numlist2[i]) + promotion))

promotion =

elifint(numlist1[i]) +int(numlist2[i]) + promotion >9:

resultstr.append(str((int(numlist1[i]) +int(numlist2[i]) + promotion) %10))

promotion =1

iflength1 > length2:

foriinrange(minlength,length1):

ifint(numlist1[i])

promotion =

resultstr.append(str(int(numlist1[i]) +1))

elifpromotion ==:

resultstr.append(numlist1[i])

elifint(numlist1[i]) ==9andpromotion ==1:

resultstr.append('0')

ifpromotion ==1:

resultstr.append('1')

resultstr.reverse()

result ="".join(resultstr)

• 发表于:
• 原文链接http://kuaibao.qq.com/s/20180304G0QTR400?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2023-03-29

2023-03-29

2023-03-29

2023-03-29

2023-03-29

10元无门槛代金券