312. Convert Array to Linked List

EasyLinked ListLinked ListArrayConstruction

Given an integer array nums, construct a singly linked list containing all elements in the same order and return the head of the list.

Each element in nums should become a node in the linked list.

Input: An integer array nums.

Output: Head of the newly constructed singly linked list.

Examples

Example 1
Input: [1,2,3,4,5]
Output: [1,2,3,4,5]
Explanation: Create nodes 1→2→3→4→5. Return head node (value=1).
Example 2
Input: [10,20,30]
Output: [10,20,30]
Explanation: Three nodes: 10→20→30. Return head(10).
Example 3
Input: [7]
Output: [7]
Explanation: Single element array → single node list.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →