<commit_before><commit_msg>LeetCode: 2. Add Two Numbers<commit_after>// since the lists are stored from least significant digits (which are both units) and the expected output likewise, we can use the normal manual addition algorithm

/**
 * 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) {
        ListNode *lSum = new ListNode(0); // dummy node for convenience
        ListNode *it1 = l1, *it2 = l2, *itSum = lSum;
        int carry = 0;
        while (it1 != NULL && it2 != NULL) {
            int sum = it1->val + it2->val + carry;
            carry = sum / 10;
            sum = sum % 10;
            itSum->next = new ListNode(sum);
            it1 = it1->next;
            it2 = it2->next;
            itSum = itSum->next;
        }
        while (it1 != NULL) { // if l1 had more digits
            int sum = it1->val + carry;
            carry = sum / 10;
            sum = sum % 10;
            itSum->next = new ListNode(sum);
            it1 = it1->next;
            itSum = itSum->next;
        }
        while (it2 != NULL) { // if l2 had more digits
            int sum = it2->val + carry;
            carry = sum / 10;
            sum = sum % 10;
            itSum->next = new ListNode(sum);
            it2 = it2->next;
            itSum = itSum->next;
        }
        if (carry > 0) {
            itSum->next = new ListNode(carry);
        }
        return lSum->next;
    }
};

{'fraction_non_alphanumeric': 0.12247474747474747, 'fraction_numerical': 0.025252525252525252, 'mean_word_length': 1.5605815831987075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7118471', 'n_tokens_mistral': 508, 'n_tokens_neox': 490, 'n_words': 154}