public ListNode addTwoNumbers(ListNode l1, ListNode l2) {

    ListNode result = new ListNode(0);

    ListNode curt1 = l1, curt2 = l2, head = result;
    int carry = 0;

    while (curt1 != null || curt2 != null) {
      if (curt1 != null) {
        carry += curt1.val;
        curt1 = curt1.next;
      }
      if (curt2 != null) {
        carry += curt2.val;
        curt2 = curt2.next;
      }
      result.next = new ListNode(carry % 10);
      result = result.next;
      carry /= 10;
    }

    if (carry == 1) {
      result.next = new ListNode(1);
    }
    return head.next;
  }