public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        if (l1 == null) {
        	return l2;
        }
        
        if (l2 == null) {
        	return l1;
        }
        
		ListNode head = new ListNode(0);
		ListNode cur = head;
        
		int flag = 0;
		while (l1 != null && l2 != null) {
			int sum = l1.val + l2.val + flag;
			cur.next = new ListNode(sum % 10);
			flag = sum/10;
			
			l1 = l1.next;
			l2 = l2.next;
			cur = cur.next;
		}
		
		cur.next = l1 != null ? l1 : l2;
		
		while (cur.next != null) {
			cur = cur.next;
			int sum = cur.val + flag;
			cur.val = sum % 10;
			flag = sum / 10;
		}
		
		if (flag == 1) {
			cur.next = new ListNode(1);
		}
		
		return head.next;
    }