let 课程地址 = " http://icourse8.com/suanfamianshi.html ";课程地址
第1章 算法面试到底是什么鬼?
第2章 面试中的复杂度分析
第3章 数组中的问题其实最常见
第4章 查找表相关问题
第5章 在链表中穿针引线
第6章 栈,队列,优先队列
第7章 二叉树和递归
第8章 递归和回溯法
第9章 动态规划基础
第10章 贪心算法
第11章 课程结语
class Solution:
def addTwoNumbers(self, l1, l2):
"""
:type l1: ListNode
:type l2: ListNode
:rtype: ListNode
"""
re = ListNode(0)
r=re
carry=0
while(l1 or l2):
x= l1.val if l1 else 0
y= l2.val if l2 else 0
s=carry+x+y
carry=s//10
r.next=ListNode(s%10)
r=r.next
if(l1!=None):l1=l1.next
if(l2!=None):l2=l2.next
if(carry>0):
r.next=ListNode(1)
return re.next