<commit_before># Definition for singly-linked list.
# class ListNode
#     attr_accessor :val, :next
#     def initialize(val)
#         @val = val
#         @next = nil
#     end
# end

# @param {ListNode} head
# @return {ListNode}
def swap_pairs(head)
    return head if head.next == nil
    current_node = head 
    next_node = current_node.next
    head = next_node

    while current_node && next_node
        next_first_node = next_node.next
        current_node.next = next_node.next.next ? next_node.next.next : next_node.next
        next_node.next = current_node
        current_node = next_first_node
        next_node = next_node.next.next
    end

    next_node.next = nil

    head
end

class NilClass
    def next
        nil
    end
    def next=(value)
        nil
    end
end<commit_msg>Use recursive solution<commit_after># Definition for singly-linked list.
# class ListNode
#     attr_accessor :val, :next
#     def initialize(val)
#         @val = val
#         @next = nil
#     end
# end

# @param {ListNode} head
# @return {ListNode}
def swap_pairs(head)
    return head if !head || !head.next
    next_pair = head.next.next
    new_head = head.next
    head.next.next = head
    head.next = swap_pairs(next_pair)
    new_head
end
{'fraction_non_alphanumeric': 0.08924302788844622, 'fraction_numerical': 0.0, 'mean_word_length': 2.4600550964187327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2101851', 'n_tokens_mistral': 421, 'n_tokens_neox': 414, 'n_words': 108}