LeetCode #2 [Add Two Numbers] In C Language Solutions
Question:
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Solutions :
This function takes in two linked lists l1 and l2, representing two non-negative integers, and returns a new linked list representing the sum of these two numbers. The digits of the input numbers are stored in reverse order, and each node of the linked lists contains a single digit. The function assumes that the input numbers do not have any leading zeros, except for the number 0 itself.
The function works by iterating through both linked lists, adding the values of the current nodes and the carry value, and storing the last digit of the sum in a new node of the resulting list. The carry value is updated for the next iteration. At the end, if there is a remaining carry value, a new node is added to the end of the resulting list.
Try again