Given a singly linked list consisting of N nodes. The task is to remove duplicates (nodes with duplicate values) from the given list (if exists).
Note: Try not to use extra space. Expected time complexity is O(N). The nodes are arranged in a sorted way.
Example 1:
Input:
LinkedList: 2->2->4->5
Output: 2 4 5
Explanation: In the given linked list 
2 ->2 -> 4-> 5, only 2 occurs more 
than 1 time.
Example 2:
Input:
LinkedList: 2->2->2->2->2
Output: 2
Explanation: In the given linked list 
2 ->2 ->2 ->2 ->2, 2 is the only element
and is repeated 5 times.
Your Task:
The task is to complete the function removeDuplicates() which should remove the duplicates from linked list and return the head of the linkedlist.
Expected Time Complexity : O(N)
Expected Auxilliary Space : O(1)
Constraints:
1 <= Number of nodes <= 10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3

'''

	Your task is to remove duplicates from given 

	sorted linked list.

	

	Function Arguments: head (head of the given linked list) 

	Return Type: none, just remove the duplicates from the list.



	{

		# Node Class

		class Node:

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

		        self.data = data

		        self.next = None

	}

'''

#Function to remove duplicates from sorted linked list.

def removeDuplicates(head):

    #code here

Solutions:
def removeDuplicates(head):
	curr = head
	while curr:
		temp = curr
		while temp and temp.data == curr.data:
			temp = temp.next
		curr.next = temp
		curr = curr.next
	return head


def removeDuplicates(head):
	if head is None or head.next is None:
		return head
	current = head
	while current.next is not None:
		if current.data == current.next.data:
			current.next = current.next.next
		else:
			current = current.next
	return head


def removeDuplicates(head):
	temp = head
	if temp is None:
		return
	while temp.next is not None:
		if temp.data == temp.next.data:
			new = temp.next.next
			temp.next = None
			temp.next = new
		else:
			temp = temp.next
	return head


def removeDuplicates(head):
	if head == None:
		return head
	curr = head
	while curr.next:
		if curr.data == curr.next.data:
			curr.next = curr.next.next
		else:
			curr = curr.next


def removeDuplicates(head):
	if head == None:
		return head
	curr1 = head
	curr2 = head.next
	while curr2 != None:
		while curr2 != None and curr1.data == curr2.data:
			curr2 = curr2.next
		curr1.next = curr2
		curr1 = curr1.next


def removeDuplicates(head):
	x = head
	while x.next:
		if x.next.data == x.data:
			x.next = x.next.next
		else:
			x = x.next


def removeDuplicates(head):
	n = head
	while n != None:
		while n.next != None and n.next.data == n.data:
			n.next = n.next.next
		n = n.next
	return head


def removeDuplicates(head):
	temp = head
	while temp.next:
		if temp.next.data == temp.data:
			temp.next = temp.next.next
		else:
			temp = temp.next


def removeDuplicates(head):
	curr = head
	if head == None:
		return -1
	while curr.next != None:
		while curr.next.data == curr.data:
			curr.next = curr.next.next
			if curr.next == None:
				return head
		if curr.next != None:
			curr = curr.next
	return head


def removeDuplicates(head):
	current = head
	while current and current.next:
		if current.data == current.next.data:
			current.next = current.next.next
		else:
			current = current.next
	return head


def removeDuplicates(head):
	current = head
	while current.next:
		if current.data == current.next.data:
			current.next = current.next.next
			continue
		current = current.next
	return head


def removeDuplicates(head):
	prev = head
	current = head.next
	while current is not None:
		if current.data != prev.data:
			prev.next = current
			prev = current
		current = current.next
	prev.next = current
	return head


def removeDuplicates(head):
	cur = head
	new_head = head
	while cur:
		if not cur.next:
			break
		nxt = cur.next
		if cur.data == nxt.data:
			while cur.data == nxt.data:
				if nxt.next is None:
					cur.next = None
					return head
				nxt = nxt.next
			cur.next = nxt
		cur = cur.next
	return head


def removeDuplicates(head):
	prev = head
	temp = prev.next
	while temp:
		if temp.data == prev.data:
			temp = temp.next
			prev.next = temp
		else:
			temp = temp.next
			prev = prev.next
	return head


def removeDuplicates(head):
	prev = None
	current = head
	setTemp = set()
	while current != None:
		if current.data in setTemp:
			temp = current.next
			prev.next = temp
			current = temp
		else:
			setTemp.add(current.data)
			prev = current
			current = current.next


def removeDuplicates(head):
	if head is None:
		return head
	prev = None
	curr = head
	while curr is not None:
		if prev is not None:
			if prev.data == curr.data:
				prev.next = curr.next
			else:
				prev = curr
		else:
			prev = curr
		curr = curr.next
	return head


def removeDuplicates(head):
	curr_node = head
	while curr_node.next:
		if curr_node.data == curr_node.next.data:
			curr_node.next = curr_node.next.next
		else:
			curr_node = curr_node.next


def removeDuplicates(head):
	cur = head
	while cur and cur.next:
		if cur.data == cur.next.data:
			cur.next = cur.next.next
		else:
			cur = cur.next
	return head


def removeDuplicates(head):
	temp = head
	while temp != None and temp.next != None:
		if temp.data == temp.next.data:
			temp.next = temp.next.next
		else:
			temp = temp.next
	return head


def removeDuplicates(head):
	itr = head
	while itr and itr.next:
		while itr.next and itr.data == itr.next.data:
			itr.next = itr.next.next
		itr = itr.next
	return head


def removeDuplicates(head):
	front = head
	while front.next is not None:
		if front.data == front.next.data:
			front.next = front.next.next
			continue
		front = front.next


def removeDuplicates(head):
	s = head
	while s.next:
		if s.next.data == s.data:
			s.next = s.next.next
		else:
			s = s.next


def removeDuplicates(head):
	c = head
	while c.next:
		l = c.data
		d = c.next.data
		if l == d:
			c.next = c.next.next
		else:
			c = c.next


def removeDuplicates(head):
	prev = head
	nxt = prev.next
	while nxt is not None:
		if prev.data == nxt.data:
			if nxt.next is None:
				prev.next = None
			nxt = nxt.next
		else:
			prev.next = nxt
			prev = nxt
			nxt = nxt.next


def removeDuplicates(head):
	if head == None and head.next == None:
		return head
	p = head
	while p:
		if p.next != None and p.data == p.next.data:
			p.next = p.next.next
		else:
			p = p.next
	return head


def removeDuplicates(head):
	ptr = head
	while ptr.next != None:
		if ptr.data == ptr.next.data:
			ptr.next = ptr.next.next
		else:
			ptr = ptr.next
	return head


def removeDuplicates(head):
	if head == None:
		return None
	prev = None
	curr = head
	while curr:
		if curr.next != None and curr.data == curr.next.data:
			prev = curr
			while curr.next != None and curr.data == curr.next.data:
				curr = curr.next
			prev.next = curr.next
		curr = curr.next
	return head


def removeDuplicates(head):
	if head is None:
		return head
	cur = head
	while cur.next:
		if cur.data == cur.next.data:
			cur.next = cur.next.next
		else:
			cur = cur.next
	return head


def removeDuplicates(head):
	prev = head
	current = prev.next
	while True:
		if current is None:
			break
		if prev.data == current.data:
			current = current.next
			prev.next = current
		else:
			prev = current
			current = current.next
	return


def removeDuplicates(head):
	curr = head
	while curr != None and curr.next != None:
		if curr.data == curr.next.data:
			curr.next = curr.next.next
		else:
			curr = curr.next


def removeDuplicates(head):
	curr = head
	while curr != None:
		temp = curr.next
		while temp != None and curr.data == temp.data:
			temp = temp.next
		curr.next = temp
		curr = curr.next


def removeDuplicates(head):
	if head is None or head.next == None:
		return
	curr = head
	while curr is not None and curr.next is not None:
		if curr.data == curr.next.data:
			curr.next = curr.next.next
		else:
			curr = curr.next


def removeDuplicates(h):
	head = h
	while head.next != None:
		if head.next.data == head.data:
			head.next = head.next.next
		else:
			head = head.next
	return h


def removeDuplicates(head):
	h = set()
	prev = None
	curr = head
	while curr:
		if curr.data in h:
			prev.next = curr.next
		else:
			h.add(curr.data)
			prev = curr
		curr = curr.next
	return head


def removeDuplicates(head):
	if head == None:
		return None
	curr = head
	while curr != None:
		if curr.next != None and curr.data == curr.next.data:
			nxt_next = curr.next.next
			curr.next = nxt_next
		else:
			curr = curr.next


def removeDuplicates(head):
	if not head:
		return None
	current = head
	after = head.next
	while current:
		while after and current.data == after.data:
			after = after.next
		current.next = after
		current = current.next
	return head


def removeDuplicates(head):
	nextt = head.next
	prev = head
	while nextt:
		if nextt.data == prev.data:
			prev.next = nextt.next
			nextt = nextt.next
		else:
			prev = prev.next
			nextt = nextt.next
	return head


def removeDuplicates(head):
	next_node = head
	while next_node:
		if next_node.next:
			if next_node.data == next_node.next.data:
				if next_node.next.next:
					next_node.next = next_node.next.next
				else:
					next_node.next = None
					next_node = next_node.next
			else:
				next_node = next_node.next
		else:
			break
	return head


def removeDuplicates(head):
	curr = head
	while curr.next:
		if curr.next.data == curr.data:
			curr.next = curr.next.next
		else:
			curr = curr.next


def removeDuplicates(head):
	f = head
	while f.next:
		if f.next.data == f.data:
			f.next = f.next.next
		else:
			f = f.next


def removeDuplicates(head):
	t = head
	while t.next != None:
		if t.next.data == t.data:
			t.next = t.next.next
		else:
			t = t.next


def removeDuplicates(head):
	temp = head
	if temp == None:
		return temp
	while temp.next != None:
		if temp.data == temp.next.data:
			n = temp.next.next
			temp.next = None
			temp.next = n
		else:
			temp = temp.next
	return temp


def removeDuplicates(head):
	l1 = head
	while head:
		if head.next != None and head.next.data == head.data:
			head.next = head.next.next
		else:
			head = head.next
	return l1


def removeDuplicates(head):
	prev = head
	curr = head.next
	while curr is not None:
		if curr is not None and curr.data == prev.data:
			prev.next = curr.next
			curr = curr.next
		elif curr is not None and curr.data != prev.data:
			prev = curr
			curr = curr.next
	return head


def removeDuplicates(head):
	temp = head
	while temp:
		cur_node = temp
		next_node = temp.next
		cur_val = cur_node.data
		next_val = None
		if next_node:
			next_val = next_node.data
		if cur_val == next_val:
			if next_node.next:
				temp.next = next_node.next
				temp = cur_node
			else:
				temp.next = None
				temp = temp.next
		else:
			temp = next_node
	return head


def removeDuplicates(h):
	if h.next == None:
		return h
	s = h
	t = h.next
	while t.next != None:
		if s.data == t.data:
			s.next = t.next
			t.next = None
			t = s.next
			continue
		s = s.next
		t = t.next
	if s.data == t.data:
		s.next = None
	return h


def removeDuplicates(start):
	temp = start
	curr = start
	while temp.next:
		if temp.data == temp.next.data:
			temp = temp.next
		else:
			curr.next = temp.next
			curr = temp.next
			temp = curr
	curr.next = None
	return curr


def removeDuplicates(start):
	temp = start
	while temp.next:
		if temp.data == temp.next.data:
			temp.next = temp.next.next
		else:
			temp = temp.next
	return start


def removeDuplicates(head):
	while head:
		cn = head
		if cn.next is not None:
			nn = cn.next
			while nn and cn.data == nn.data:
				nn = nn.next
			head.next = nn
		head = head.next


def removeDuplicates(head):
	cur = head
	while cur != None and cur.next != None:
		if cur.data == cur.next.data:
			cur.next = cur.next.next
		else:
			cur = cur.next


def removeDuplicates(head):
	if head == None or head.next == None:
		return head
	prev = head
	cur = head
	while cur:
		if cur.data == prev.data:
			cur = cur.next
		else:
			prev.next = cur
			prev = cur
			cur = cur.next
	prev.next = cur
	return head


def removeDuplicates(head):
	temp = head
	while temp != None:
		value = temp.data
		ctr = temp.next
		if ctr is None:
			return head
		while ctr.data == value:
			ctr = ctr.next
			if ctr is None:
				break
		temp.next = ctr
		temp = ctr
	return head


def removeDuplicates(head):
	prev = None
	curr = head
	while curr:
		if prev:
			if prev.data == curr.data:
				next = curr.next
				prev.next = next
				del curr
				curr = next
				continue
		prev = curr
		curr = curr.next
	return head


def removeDuplicates(head):
	current = head
	while current.next:
		if current.data == current.next.data:
			current.next = current.next.next
		else:
			current = current.next


class Node:

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

def removeDuplicates(head):
	curr = head
	while curr and curr.next:
		if curr.data == curr.next.data:
			curr.next = curr.next.next
		else:
			curr = curr.next
	return head