/**
 Definition for singlylinked list.
 public class ListNode {

int val;

ListNode next;

ListNode(int x) { val = x; }
 }
*/
public class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
int carry = 0;
int temp = l1.val + l2.val + carry;
l1 = l1.next;
l2 = l2.next;
carry = temp / 10;
ListNode result = new ListNode(tempcarry*10);
ListNode tempp = result;
while (l1 != null && l2 != null) {
temp = l1.val + l2.val + carry;
l1 = l1.next;
l2 = l2.next;
carry = temp / 10;
result.next = new ListNode(tempcarry*10);
result = result.next;
}
while (l1 != null) {
temp = l1.val + carry;
l1 = l1.next;
carry = temp / 10;
result.next = new ListNode(tempcarry*10);
result = result.next;
}
while (l2 != null) {
temp = l2.val + carry;
l2 = l2.next;
carry = temp / 10;
result.next = new ListNode(tempcarry*10);
result = result.next;
}
if (carry == 1) {
result.next = new ListNode(1);
}
return tempp;
}
}