Preview:
void insertAtTail(Node* &tail,int d)
 {
   Node* temp = new Node(d);
   tail->next = temp;
   tail = tail->next;
 }

Node* constructLL(vector<int>& arr) {
    // Write your code here
    Node* head = new Node(arr[0]);
    Node* tail = head;
    
    for(int i = 1;i<arr.size();i++)
    {
      insertAtTail(tail,arr[i]);
    }
    return head;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter