The Sum and the decision for the next carry-over, Carry out, are determined by three inputs: input values A and B, and the previous carry-over, Carry in.
A
B
Carry in
Sum
Carry out
0
0
0
0
0
0
0
1
1
0
0
1
0
1
0
0
1
1
0
1
1
0
0
1
0
1
0
1
0
1
1
1
0
0
1
1
1
1
1
1
Solution:
Data type conversion
Reverse the given linked lists
Convert the linked list to integer.
Add the numbers.
Convert the sum to a string.
Create a new linked list from the sum.
Return the result linked list.
A little different code, but same logic
What to learn from this code?
How to make a reversed linked list
How to convert a string list into a string
Full Adder
Original adders perform binary operations using logical circuits, but here we can implement it in a manner similar to a full adder of logical circuits using decimal operations.
We will solve it by referring only to the overall structure of the full adder, which takes the remainder as the operation result and raises the quotient in the form of a carry.
l1, l2 play the same role as A, B in the figure above, performing operations on the two input values, and if the digits overflow as follows, a carry is set.
If the addition result becomes two digits, the quotient is set as a carry to be used in the next operation, and the remainder is taken as the value.