/**

Definition for singlylinked list.

public class ListNode {

int val;

ListNode next;

ListNode(int x) {

val = x;

next = null;

}

}
*/
public class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
return addTwoNumbersWithCarryOver(l1,l2,0);
}public ListNode addTwoNumbersWithCarryOver(ListNode l1,ListNode l2, int carryOver){
if (l1 == null) {
return carryOver == 0 ? l2 : addTwoNumbersWithCarryOver(new ListNode(carryOver), l2,0);
}if (l2 == null) { return carryOver == 0 ? l1 : addTwoNumbersWithCarryOver(l1, new ListNode(carryOver),0); } int sumVal = l1.val + l2.val + carryOver; ListNode returnVal = new ListNode(sumVal%10); returnVal.next = addTwoNumbersWithCarryOver(l1.next,l2.next, sumVal/10); return returnVal;
}
}