class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
ListNode demo=new ListNode(0);
ListNode temp1=l1,temp2=l2,cur=demo;
//进位
int addnote=0;
while(temp1!=null||temp2!=null){
int temp=0;
if(temp1!=null){
temp+=temp1.val;
temp1=temp1.next;
}
if(temp2!=null){
temp+=temp2.val;
temp2=temp2.next;
}
temp+=addnote;
addnote=0;
if(temp>=10){
temp-=10;
addnote=1;
}
cur.next=new ListNode(temp);
cur=cur.next;
//考虑到若最后一位为0但却有进位的情况
if(temp1==null&&temp2==null&&addnote==1){
cur.next=new ListNode(addnote);
cur=cur.next;
}
}
return demo.next;
}
}