题解 | #子数组的最大累加和问题#

两个链表生成相加链表

http://www.nowcoder.com/practice/c56f6c70fb3f4849bc56e33ff2a50b6b

class Solution:
def addInList(self , head1 , head2 ):
# write code here
sum1=''
sum2=''
while head1 is not None:
p=head1.next
f=head1.val
head1=p
sum1+=str(f)
while head2 is not None:
s=head2.next
j=head2.val
head2=s
sum2+=str(j)
t=int(sum1)+int(sum2)
t=str(t)
s=ListNode(int(t[0]))
self.head3=ListNode(int(t[0]))
p=self.head3
for i in range(1,len(t)):
node=ListNode(int(t[i]))
p.next=node
p=p.next
return self.head3

全部评论

相关推荐

飞花断音:这个头像有点搞笑
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务