✔️ 100% Fastest Swift Solution, time: O(n log n), space: O(n).
\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     public var val: Int\n *     public var next: ListNode?\n *     public init() { 
```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     public var val: Int\n *     public var next: ListNode?\n *     public init() { self.val = 0; self.next = nil; }\n *     public init(_ val: Int) { self.val = val; self.next = nil; }\n *     public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n    // - Complexity:\n    //   - time: O(n log n), where n is the number of nodes in the linked list.\n    //   - space: O(n)\n    \n    func insertionSortList(_ head: ListNode?) -> ListNode? {\n        var nodes: [ListNode] = []\n        var curr = head\n        \n        while curr != nil {\n            nodes.append(curr!)\n            curr = curr?.next\n        }\n        \n        nodes.sort(by: { $0.val < $1.val })\n        \n        var newHead: ListNode?\n        var prev: ListNode?\n        \n        for node in nodes {\n            if newHead == nil {\n                newHead = node\n            }\n            \n            prev?.next = node\n            prev = node\n        }\n        \n        prev?.next = nil\n        return newHead\n    }\n\n}\n```\n\nLet me know in comments if you have any doubts. I will be happy to answer.\n\nPlease upvote if you found the solution useful.
['Swift']