2. 两数相加

class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
       ListNode curr = new ListNode(0);
        ListNode head = curr;
        int plus =0;
        while (l1 != null || l2!=null || plus !=0){
            int a = l1==null?0:l1.val;
            int b = l2==null?0:l2.val;
            int res  = (a + b + plus)%10;
            plus  = (a+ b +plus)/10;
            curr.next = new ListNode(res);
            curr = curr.next;
            if(l1 != null) l1 = l1.next;
            if(l2 != null) l2 = l2.next;
        }
        return head.next;
    }
}

热门相关:大爱晚成,卯上天价老婆   腹黑老公,请离婚!   辰少的霸道专宠:强婚88次   吹神   看上朋友丈夫后的交换