# Understandable Java Solution Using Traverse

• ``````public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
int onelength = obtainListLength(l1);
int twolength = obtainListLength(l2);
int maxlength = 0;//最大数位
ListNode listone = l1;
ListNode listtwo = l2;
if(onelength>=twolength){
maxlength = onelength;
ListNode tmpNode = l2;
for(int i=0;i<onelength-twolength;i++){
ListNode tmpNode2 = tmpNode;
tmpNode = new ListNode(0);
tmpNode.next = tmpNode2;
}
listtwo = tmpNode;
}else {
maxlength = twolength;
ListNode tmpNode = l1;
for(int i=0;i<twolength-onelength;i++){
ListNode tmpNode1 = tmpNode;
tmpNode = new ListNode(0);
tmpNode.next = tmpNode1;
}
listone = tmpNode;
}
int[] signalArray = new int[maxlength+1];
int[] valueArray = new int[maxlength+1];
signalArray[maxlength] = 0;
for(int i=1;i<=maxlength;i++){
int value = listone.val + listtwo.val;
if(value >= 10){
valueArray[i] = value%10;
signalArray[i-1] = 1;
}else {
valueArray[i] = value;
signalArray[i-1] = 0;
}
listone = listone.next;
listtwo = listtwo.next;
}
for(int i=maxlength;i>=0;i--){
int value = valueArray[i]+signalArray[i];
if(value>=10){
valueArray[i] = value%10;
signalArray[i-1] = signalArray[i-1]+1;
}else {
valueArray[i] = value;
}
}
ListNode current = null;
for(int i=0;i<=maxlength;i++){
if(i==0&&valueArray[i] == 0){
continue;
}
if(i==0&&valueArray[i] != 0){
}
if(i==1&&valueArray[0] == 0){
}
if(i==1&&valueArray[0] != 0){
current.next = new ListNode(valueArray[1]);
current = current.next;
}
if(i>=2){
current.next = new ListNode(valueArray[i]);
current = current.next;
}
}
}

private int obtainListLength(ListNode listNode){