<commit_before>/**
 * Question Link: https://leetcode.com/problems/partition-list/
 * Primary idea: Tail Insert and merge two lists
 *
 * Note: Swift provides "!==" to determine two objects refer to the same reference
 * 
 * Time Complexity: O(n), Space Complexity: O(1)
 * Definition for singly-linked list.
 * public class ListNode {
 *     public var val: Int
 *     public var next: ListNode?
 *     public init(_ val: Int) {
 *         self.val = val
 *         self.next = nil
 *     }
 * }
 */

class PartitionList {
    func partition(head: ListNode?, _ x: Int) -> ListNode? {
        let prevDummy = ListNode(0)
        var prev: ListNode? = prevDummy
        let postDummy = ListNode(0)
        var post: ListNode? = postDummy
        
        var node = head
        
        while node != nil {
            if node!.val < x {
                prev!.next = node
                prev = prev!.next
            } else {
                post!.next = node
                post = post!.next
            }
            
            node = node!.next
        }
        
        post!.next = nil
        prev!.next = postDummy.next
        
        return prevDummy.next
    }
}<commit_msg>[LinkedList] fix variable style of Partition List<commit_after>/**
 * Question Link: https://leetcode.com/problems/partition-list/
 * Primary idea: Tail Insert and merge two lists
 *
 * Note: Swift provides "!==" to determine two objects refer to the same reference
 * 
 * Time Complexity: O(n), Space Complexity: O(1)
 * Definition for singly-linked list.
 * public class ListNode {
 *     public var val: Int
 *     public var next: ListNode?
 *     public init(_ val: Int) {
 *         self.val = val
 *         self.next = nil
 *     }
 * }
 */

class PartitionList {
    func partition(head: ListNode?, _ x: Int) -> ListNode? {
        let prevDummy = ListNode(0)
        var prev = prevDummy
        let postDummy = ListNode(0)
        var post = postDummy
        
        var node = head
        
        while node != nil {
            if node!.val < x {
                prev.next = node
                prev = node!
            } else {
                post.next = node
                post = node!
            }
            
            node = node!.next
        }
        
        post.next = nil
        prev.next = postDummy.next
        
        return prevDummy.next
    }
}
{'fraction_non_alphanumeric': 0.09915966386554621, 'fraction_numerical': 0.0025210084033613447, 'mean_word_length': 1.5142555438225977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1758177', 'n_tokens_mistral': 699, 'n_tokens_neox': 672, 'n_words': 206}