Skip to content

Instantly share code, notes, and snippets.

@NeraSnow
Created February 22, 2019 06:46
Show Gist options
  • Save NeraSnow/056d8ea504fd1507d49858e260a5035b to your computer and use it in GitHub Desktop.
Save NeraSnow/056d8ea504fd1507d49858e260a5035b to your computer and use it in GitHub Desktop.
LeetCode 2. Add Two Numbers draft
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
ListNote* head = new ListNode;
while(l1->next != NULL && l2->next != NULL)
{
if (l1->next == NULL)
l1Val = l1->val;
l2Val = l2->val;
bool carryOver = false;
int sum = l1Val + l2Val;
if (sum > 10)
{
sum %= 10;
carryOver = true;
}
ListNode* nextNode = new ListNode(sum);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment