<commit_before>//
//  ReverseList.swift
//  LeetCode
//
//  Created by 黄伯驹 on 2021/10/31.
//  Copyright © 2021 <NAME>. All rights reserved.
//

import Foundation

// https://leetcode-cn.com/problems/reverse-linked-list/submissions/
func reverseList(_ head: ListNode?) -> ListNode? {
    var result: ListNode?
    var head = head

    while head != nil {
        let next = head?.next
        head?.next = result
        result = head
        head = next
    }

    return result
}
<commit_msg>ReverseBetween<commit_after>//
//  ReverseList.swift
//  LeetCode
//
//  Created by 黄伯驹 on 2021/10/31.
//  Copyright © 2021 <NAME>. All rights reserved.
//

import Foundation

// https://leetcode-cn.com/problems/reverse-linked-list/submissions/
func reverseList(_ head: ListNode?) -> ListNode? {
    var result: ListNode?
    var head = head

    while head != nil {
        let next = head?.next
        head?.next = result
        result = head
        head = next
    }

    return result
}

class ReverseBetween {
    func reverseBetween(_ head: ListNode?, _ left: Int, _ right: Int) -> ListNode? {
        let dummy = ListNode(-1)
        dummy.next = head
        var node: ListNode? = dummy

        for _ in 0 ..< left - 1 {
            node = node?.next
        }
        let firstNode = node
        let midNode = firstNode?.next

        for _ in 0 ... right - left {
            node = node?.next
        }
        let thirdNode = node?.next

        firstNode?.next = nil
        node?.next = nil

        _ = reverseLink(midNode)

        firstNode?.next = node
        midNode?.next = thirdNode

        return dummy.next
    }

    func reverseLink(_ head: ListNode?) -> ListNode? {
        var result: ListNode?
        var node = head
        while node != nil {
            let next = node?.next
            node?.next = result
            result = node
            node = next
        }
        return result
    }
}

{'fraction_non_alphanumeric': 0.11139896373056994, 'fraction_numerical': 0.014507772020725389, 'mean_word_length': 1.6819444444444445, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '2139705', 'n_tokens_mistral': 621, 'n_tokens_neox': 575, 'n_words': 165}