Geek loves linked list data structure. Given an array of integer arr of size n, Geek wants to construct the linked list from arr.
Construct the linked list from arr and return the head of the linked list.
Example 1:
Input:
n = 5
arr = [1,2,3,4,5]
Output:
1 2 3 4 5
Explanation: Linked list for the given array will be 1->2->3->4->5.
Example 2:
Input:
n = 2
arr = [2,4]
Output:
2 4
Explanation: Linked list for the given array will be 2->4.
Constraints:
1 <= n <= 10^{5}
1 <= arr[i] <= 100
Your Task:
You don't need to read input or print anything. Your task is to complete the function constructLL() which takes arr[] as input parameters and returns the head of the Linked List.
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(n)

Source: geeksforgeeks | Difficulty: EASY

Starter code: #User function Template for python3



'''

# Node Class

	class Node:

	    def __init__(self, data):   # data -> value stored in node

	        self.data = data

	        self.next = None

'''

class Solution:

    def constructLL(self, arr):

        # code here

Solutions:
class Solution:

	def __init__(self):
		self.head = None
		self.tail = None

	def constructLL(self, arr):
		for x in arr:
			new_node = Node(x)
			if self.head is None:
				self.head = new_node
				self.tail = new_node
			else:
				self.tail.next = new_node
				self.tail = new_node
		return self.head


class Solution:

	def constructLL(self, arr):
		if len(arr) == 0:
			return None
		head = Node(arr[0])
		prev = head
		for i in range(1, len(arr)):
			curr = Node(arr[i])
			prev.next = curr
			prev = curr
		return head


class Solution:

	def constructLL(self, arr):
		self.head = None
		self.last = None
		for i in range(len(arr)):
			if self.head == None:
				self.head = Node(arr[i])
				self.last = self.head
			else:
				self.last.next = Node(arr[i])
				self.last = self.last.next
		return self.head


class Solution:

	def constructLL(self, arr):
		head = Node(arr[0])
		itr = head
		for i in range(1, len(arr)):
			itr.next = Node(arr[i])
			itr = itr.next
		return head


class Solution:

	def __init__(self):
		self.head = None
		self.tail = None

	def constructLL(self, arr):
		for i in range(len(arr)):
			new_node = Node(arr[i])
			if self.head is None:
				self.head = new_node
				self.tail = new_node
			else:
				self.tail.next = new_node
				self.tail = new_node
		return self.head


class Solution:

	def constructLL(self, arr):
		head = Node
		cur = head
		for i in arr:
			cur.data = i
			new = Node
			cur.next = new
			print(cur.data, end=' ')
			cur = new


class Node:

	def __init__(self, data=None, next=None):
		self.data = data
		self.next = next

class Solution:

	def __init__(self):
		self.head = None

	def constructLL(self, arr):
		self.head = Node(arr[0])
		current = self.head
		for i in range(1, len(arr)):
			newNode = Node(arr[i])
			current.next = newNode
			current = current.next
		return self.head


class Solution:

	def constructLL(self, arr):
		t = Node(arr[0])
		ans = t
		if len(arr) > 1:
			for x in arr[1:]:
				t.next = Node(x)
				t = t.next
		return ans


class Solution:

	def constructLL(self, arr):
		self.head = None
		for ele in arr:
			new_node = Node(ele)
			if self.head is None:
				self.head = new_node
				self.last = new_node
			else:
				self.last.next = new_node
				self.last = self.last.next
		return self.head


class Solution:

	def constructLL(self, arr):
		a = Node(arr[0])
		b = a
		for i in range(1, len(arr)):
			t = Node(arr[i])
			a.next = t
			a = a.next
		return b


class Solution:

	def constructLL(self, arr):
		if not arr:
			return None
		head = Node(arr[0])
		current = head
		for i in range(1, len(arr)):
			node = Node(arr[i])
			current.next = node
			current = node
		return head


class Solution:

	def constructLL(self, arr):
		h = Node(arr[0])
		c = h
		for i in range(1, len(arr)):
			c.next = Node(arr[i])
			c = c.next
		return h


class Solution:

	def constructLL(self, arr):
		ll = Node(arr[-1])
		for i in range(-2, -len(arr) - 1, -1):
			node = Node(arr[i])
			node.next = ll
			ll = node
		return ll


class Solution:

	def constructLL(self, arr):
		head = Node(arr[0])
		res = head
		arr = arr[1:]
		for i in range(len(arr)):
			res.next = Node(arr[i])
			res = res.next


class Solution:

	def constructLL(self, arr):
		if len(arr) > 0:
			head = Node(arr[0])
			t = head
			for i in range(1, len(arr)):
				t.next = Node(arr[i])
				t = t.next
			return head
		return none


class Solution(object):

	def constructLL(self, nums):
		dummy = curr = Node(None)
		for val in nums:
			curr.next = Node(val)
			curr = curr.next
		return dummy.next


class Solution:

	def constructLL(self, arr):
		head = None
		for i in range(0, len(arr)):
			temp = Node(arr[i])
			if head == None:
				head = temp
				n = head
			else:
				n.next = temp
				n = n.next
		return head


class Solution:

	def constructLL(self, arr):
		dummy = Node(0)
		head = dummy
		for i in arr:
			dummy.next = Node(i)
			dummy = dummy.next
		return head.next


class Solution:

	def constructLL(self, arr):
		head = Node(0)
		curr = head
		for ele in arr:
			temp = Node(ele)
			curr.next = temp
			curr = temp
		return head.next


class Solution:

	def constructLL(self, arr):
		for i in range(len(arr)):
			if i == 0:
				node = Node(arr[i])
				head = node
			else:
				node.next = Node(arr[i])
				node = node.next
		return head


class Node:

	def __init__(self, data):
		self.data = data
		self.next = None

class Solution:

	def constructLL(self, arr):
		self.head = None
		self.tail = None
		for i in arr:
			newNode = Node(i)
			if self.head == None:
				self.head = newNode
				self.tail = newNode
			else:
				newNode.next = None
				self.tail.next = newNode
				self.tail = newNode
		return self.head


class Solution:

	def constructLL(self, arr):
		head = Node(arr[0])
		temp = head
		for i in range(1, n):
			head.next = Node(arr[i])
			head = head.next
		return temp


class Solution:

	def constructLL(self, arr):
		node = Node(arr[0])
		node3 = node
		for i in range(1, len(arr)):
			node2 = Node(arr[i])
			node.next = node2
			node = node2
		return node3


class Solution:

	def constructLL(self, arr):
		ll_arr = []
		for i in range(len(arr)):
			object = Node(arr[i])
			ll_arr.append(object)
		for i in range(len(arr) - 1):
			ll_arr[i].next = ll_arr[i + 1]
		head = ll_arr[0]
		return head


class Solution:

	def constructLL(self, arr):
		head = Node(arr[0])
		originalhead = head
		for val in arr[1:]:
			head.next = Node(val)
			head = head.next
		return originalhead


class Solution:

	def constructLL(self, arr):
		head = None
		for i in arr:
			new = Node(i)
			if head == None:
				head = new
				temp = new
			else:
				temp.next = new
				temp = temp.next
		return head


class Solution:

	def constructLL(self, arr):
		self.head = None
		self.tail = None
		self.size = 0
		for i in arr:
			if self.tail == None:
				newNode = Node(i)
				self.head = newNode
				self.tail = newNode
				self.size += 1
			else:
				newNode = Node(i)
				self.tail.next = newNode
				self.tail = newNode
				self.size += 1
		return self.head


class Solution:

	def constructLL(self, arr):
		node = Node(arr[0])
		temp = node
		for i in arr[1:]:
			temp.next = Node(i)
			temp = temp.next
		return node


class Node:

	def __init__(self, val):
		self.val = val
		self.next = None

class Solution:

	def constructLL(self, arr):
		if not arr:
			return None
		head = Node(arr[0])
		curr = head
		for val in arr[1:]:
			node = Node(val)
			curr.next = node
			curr = curr.next
		return head


class Solution:

	def constructLL(self, arr):
		head = Node(arr[0])
		curr = head
		for i in arr[1:]:
			newNode = Node(i)
			curr.next = newNode
			curr = curr.next
		return head


class Node:

	def __init__(self, data):
		self.data = data
		self.next = None

class Solution:

	def __init__(self):
		self.head = None
		self.tail = None

	def insertNode(self, data):
		node = Node(data)
		if self.head == None:
			self.head = node
			self.tail = node
		else:
			self.tail.next = node
			self.tail = node

	def constructLL(self, arr):
		for item in arr:
			self.insertNode(item)
		return self.head


class Solution:

	def constructLL(self, arr):
		root = Node(arr[0])
		cur = root
		for i in range(1, len(arr)):
			cur.next = Node(arr[i])
			cur = cur.next
		return root


class Node:

	def __init__(self, data):
		self.data = data
		self.next = None

class LinkedList:

	def __init__(self, head=None):
		self.head = head
		self.current = head

	def append(self, Node):
		while self.current.next != None:
			self.current = self.current.next
		self.current.next = Node

class Solution:

	def constructLL(self, arr):
		nodes = []
		for num in arr:
			node = Node(num)
			nodes.append(node)
		linked_list = LinkedList(nodes[0])
		for i in range(1, len(nodes)):
			linked_list.append(nodes[i])
		return linked_list.head


class Solution:

	def constructLL(self, arr):
		dummy = Node(-1)
		p = dummy
		i = 0
		while i < len(arr):
			dummy.next = Node(arr[i])
			dummy = dummy.next
			i = i + 1
		return p.next


class Solution:

	def constructLL(self, arr):
		h = Node(arr[0])
		temp = h
		for a in range(1, len(arr)):
			o = Node(arr[a])
			temp.next = o
			temp = temp.next
		return h


class Solution:

	def constructLL(self, arr):
		dummy = Node(0)
		prev = dummy
		for i in arr:
			temp = Node(i)
			prev.next = temp
			prev = temp
		return dummy.next


class Solution:

	def constructLL(self, arr):
		self.start = Node(arr[0])
		self.ptr = self.start
		for i in range(1, len(arr)):
			self.ptr.next = Node(arr[i])
			self.ptr = self.ptr.next
		return self.start


class Solution:

	def constructLL(self, arr):
		head = None
		cur = head
		for i in arr:
			if head is None:
				head = Node(i)
				cur = head
			else:
				cur.next = Node(i)
				cur = cur.next
		return head


class Solution:

	def constructLL(self, arr):
		if not arr:
			return
		else:
			head = Node(arr[0])
			temp_head = head
			for i in range(1, len(arr)):
				temp_head.next = Node(arr[i])
				temp_head = temp_head.next
			return head


class Solution:

	def constructLL(self, arr):
		for i in arr:
			print(i, end=' ')


class Solution:

	def constructLL(self, arr):
		if len(arr) == 1:
			return Node(arr[-1])
		head = Node(arr[0])
		tmp = head
		arr.pop(0)
		for i in range(len(arr)):
			tmp.next = Node(arr[i])
			if i == len(arr) - 1:
				tmp.next.next = None
				return head
			tmp = tmp.next


class Node:

	def __init__(self, data):
		self.data = data
		self.next = None

class Solution:

	def constructLL(self, arr):
		self.head = Node(arr[0])
		temp = self.head
		for i in range(1, len(arr)):
			curr = Node(arr[i])
			temp.next = curr
			temp = temp.next
		return self.head


class Solution:

	def constructLL(self, arr):
		head = None
		t = None
		for i in arr:
			if head == None:
				head = Node(i)
				t = head
			else:
				t.next = Node(i)
				t = t.next
		return head


class Solution:

	def constructLL(self, arr):
		head = None
		for val in arr:
			if not head:
				head = temp = Node(val)
			else:
				temp.next = Node(val)
				temp = temp.next
		return head


class Node:

	def __init__(self, data):
		self.data = data
		self.next = None

class Solution:

	def __init__(self):
		self.head = None

	def constructLL(self, arr):
		for i in range(len(arr) - 1, -1, -1):
			new_node = Node(arr[i])
			new_node.next = self.head
			self.head = new_node
		return self.head


class Solution:

	def constructLL(self, arr):
		if len(arr) == 0:
			return NULL
		head = Node(arr[0])
		temp = head
		for i in range(1, len(arr)):
			new = Node(arr[i])
			head.next = new
			head = head.next
		return temp


class Solution:

	def constructLL(self, arr):
		for i in range(len(arr)):
			temp = Node(arr[i])
			print(temp.data, end=' ')
			temp = temp.next


class Solution:

	def constructLL(self, arr):
		ob = Node(arr[0])
		n = len(arr)
		res = ob
		i = 1
		while i < n:
			ob.next = Node(arr[i])
			ob = ob.next
			i = i + 1
		return res


class Solution:

	def constructLL(self, arr):
		head = Node(arr[0])
		temp = head
		for i in arr[1:]:
			temp1 = Node(i)
			temp.next = temp1
			temp = temp.next
		return head


class Solution:

	def constructLL(self, arr):
		self.arr = None
		head = Node(arr[0])
		p = head
		for i in arr[1:]:
			temp = Node(i)
			p.next = temp
			p = p.next
		return head


class Solution:

	def constructLL(self, arr):
		head = Node(arr[0])
		n = len(arr)
		curr = head
		for i in range(1, n):
			new_node = Node(arr[i])
			curr.next = new_node
			curr = curr.next
		return head


class Solution:

	def constructLL(self, arr):
		head = None
		for i in arr:
			if not head:
				head = Node(i)
				statingPoint = head
				continue
			head.next = Node(i)
			head = head.next
		return statingPoint