Given the head of a singly linked list, convert it to an array (list) and return the array containing all node values in the same order from head to tail.
Traverse the list once and collect all values.
Input: Head of a singly linked list.
Output: An array of integers representing node values from head to tail.
Input: [1,2,3,4,5]
Output: [1,2,3,4,5]
Explanation: Traverse: 1→2→3→4→5→NULL. Collect [1,2,3,4,5].Input: [10,20,30]
Output: [10,20,30]
Explanation: Traverse: 10→20→30→NULL. Collect [10,20,30].Input: [7]
Output: [7]
Explanation: Single node. Collect [7].1 <= number of nodes <= 10^5-10^9 <= Node.val <= 10^9