请教前辈问题点,我print出来的值都会有None。试过有给temp list 初始值[0,0],结果
还是会多个None。还请前辈们指点。此问题是从Leetcode 第二题 addTwoNumber出来的。
def addTwoNumbers( l1, l2,temp):
    carry = 0
    for i in range(len(l1)):
        if (l1[i]+l2[i])+carry>=10:
            if carry==0:
                temp.append((l1[i]+l2[i])%10)
                carry=1
            else:
                temp.append((l1[i]+l2[i])%10+carry)
                carry=1
        else:
            temp.append((l1[i]+l2[i])%10+carry)
            carry=0
    if carry==1:
        temp.append(1)
    print(temp)
list1=[1,1]
list2=[1,1]
list=[]
a=addTwoNumbers(list1,list2,list)
print(a)
You have already passed list into function, you can just get final result from that list. Also, your function doesn’t return any value, that’s why it print None