Sobes.tech
Intern — Senior

Collect singly linked list nodes into an array

livecode

Task condition

It is necessary to traverse a singly linked list starting from its first node and collect all nodes into an array, preserving their order.

class ListNode {
    let data: Int
    let next: ListNode?

    init(data: Int, next: ListNode?) {
        self.data = data
        self.next = next
    }
}

class Solution {
    public static func convert(head: ListNode) -> [ListNode] {
        
    }
}