Simple [JAVA] solution


#1
public class Solution {
public ListNode addTwoNumbers(ListNode A, ListNode B) {
    ListNode result = new ListNode(0);
    ListNode p = result;
    int carry =0;
    while (A != null || B != null || carry != 0){
        if(A != null){
            carry += A.val;
            A = A.next;
        }
        if(B != null){
            carry += B.val;
            B = B.next;
        }
        p.next = new ListNode(carry % 10);
        carry /= 10;
        p = p.next;
    }
    return result.next;
    
}
}