You are given the `head` of a singly linked list. Each node in the linked list has an integer `val` and a pointer `next` to the next node. Your task is to implement a function that recursively traverses the linked list from the `head` and collects all node values into a new list (e.g., an array or ArrayList) in the order they appear. The function should return this collected list.
Explanation: The function recursively visits each node, collecting its value into a list in traversal order.
Explanation: The list contains only one node, so its value is collected.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak