Given a Singly Linked List of size N, delete all alternate nodes of the list.
Example 1:
Input:
LinkedList: 1->2->3->4->5->6
Output: 1->3->5
Explanation: Deleting alternate nodes
results in the linked list with elements
1->3->5.
 
Example 2:
Input:
LinkedList: 99->59->42->20
Output: 99->42
 
Your Task:
Your task is to complete the function deleteAlt() which takes the head of the linked list in the input parameter and modifies the given linked list accordingly.
 
Constraints:
1<=N<=100
 
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3



'''class Node: 

   

    # Function to initialize the node object 

    def __init__(self, data): 

        self.data = data  

        self.next = None'''



class Solution: 

    

    

    def deleteAlt(self, head):

        

        #add code here

Solutions:
class Solution:

	def deleteAlt(self, head):
		h = head
		while h != None and h.next != None:
			h.next = h.next.next
			if h == None:
				return head
			h = h.next
		return head


class Solution:

	def deleteAlt(self, head):
		curr = head
		while curr != None and curr.next != None:
			curr.next = curr.next.next
			curr = curr.next
		return head


class Solution:

	def deleteAlt(self, head):
		temp = head
		while temp and temp.next:
			temp.next = temp.next.next
			temp = temp.next
		return head


class Solution:

	def deleteAlt(self, head):
		n = head
		while n != None and n.next != None:
			n.next = n.next.next
			n = n.next
		return head


class Solution:

	def deleteAlt(self, head):
		dummy = head
		while dummy and dummy.next:
			dummy.next = dummy.next.next
			dummy = dummy.next
		return head


class Solution:

	def deleteAlt(self, head):
		a = head
		while a != None and a.next != None:
			a.next = a.next.next
			a = a.next
		return head


class Solution:

	def deleteAlt(self, head):
		temp = head
		f = head
		while f:
			if f:
				f = f.next
				if f:
					f = f.next
			temp.next = f
			temp = f
		return head


class Solution:

	def deleteAlt(self, head):
		if head is None:
			return
		count = 0
		temp = head
		while temp:
			count += 1
			temp = temp.next
		for i in range(1, count, 1):
			if head and head.next:
				next_node = head.next.next
				head.next = next_node
				head = next_node


class Solution:

	def deleteAlt(self, head):
		next_node = head
		while next_node:
			if next_node.next:
				if next_node.next.next:
					next_node.next = next_node.next.next
					next_node = next_node.next
				else:
					next_node.next = None
					next_node = next_node.next
			else:
				break
		return head


class Solution:

	def deleteAlt(self, head):
		flag = True
		temp = head
		while temp and temp.next:
			cur = temp.next
			if flag == True:
				temp.next = cur.next
			temp = cur
			flag = not flag
		return head


class Solution:

	def deleteAlt(self, head):
		slow = head
		while slow != None and slow.next != None:
			slow.next = slow.next.next
			slow = slow.next


class Solution:

	def deleteAlt(self, head):
		temp = head
		while temp != None and temp.next != None:
			temp.next = temp.next.next
			temp = temp.next


class Solution:

	def deleteAlt(self, head):
		node = head
		while node != None and node.next != None:
			node.next = node.next.next
			node = node.next


class Solution:

	def deleteAlt(self, head):
		cur = head
		while cur:
			if cur.next is None:
				break
			if cur.next.next:
				cur.next = cur.next.next
			else:
				cur.next = None
			cur = cur.next
		return head


class Solution:

	def deleteAlt(self, head):
		temp = head
		while temp != None:
			if temp.next != None:
				temp.next = temp.next.next
				temp = temp.next
			else:
				return head
		return head


class Solution:

	def deleteAlt(self, head):
		ptr = head
		while ptr.next and ptr.next.next:
			prev = ptr
			ptr = ptr.next.next
			prev.next = ptr
		ptr.next = None
		return head


class Solution:

	def deleteAlt(self, head):
		if head is None:
			return None
		prev = head
		current = head.next
		while prev is not None and current is not None:
			prev.next = current.next
			prev = prev.next
			if prev is not None:
				current = prev.next
		return head


class Solution:

	def deleteAlt(self, head):
		while head is not None:
			if head.next is not None:
				head.next = head.next.next
			head = head.next


class Solution:

	def deleteAlt(self, head):
		n = head
		while n is not None:
			if n.next is not None:
				n.next = n.next.next
				n = n.next
			else:
				break
		return head


class Solution:

	def deleteAlt(self, head):
		curr = head
		c = 0
		while curr != None:
			c += 1
			curr = curr.next
		if c % 2 == 0:
			curr = head
			while curr.next.next != None:
				curr.next = curr.next.next
				curr = curr.next
			curr.next = None
			return head
		else:
			curr = head
			while curr.next != None:
				curr.next = curr.next.next
				curr = curr.next
			return head


class Solution:

	def deleteAlt(self, head):
		current = head
		previous = None
		while current:
			previous = current
			current = current.next
			if current:
				previous.next = current.next
				current = previous.next


class Solution:

	def deleteAlt(self, head):
		t = head
		while t != None and t.next != None:
			t.next = t.next.next
			t = t.next
		return head


class Solution:

	def deleteAlt(self, head):
		while head and head.next:
			head.next = head.next.next
			head = head.next


class Solution:

	def deleteAlt(self, head):
		temp = head
		c = 1
		while temp:
			if temp.next is not None:
				a = temp.next
				c = c + 1
				if c % 2 == 0:
					temp.next = a.next
					c = 1
			temp = temp.next
		return head


class Solution:

	def deleteAlt(self, head):
		current = head
		current_next = None
		current_next_next = None
		while current != None:
			try:
				current_next = current.next
				current_next_next = current_next.next
				current.next = current_next_next
				current = current.next
			except:
				return head
		return head


class Solution:

	def deleteAlt(self, head):
		h = head
		while head and head.next:
			a = head.next.next
			head.next = a
			head = head.next
		return h


class Solution:

	def deleteAlt(self, head):
		if head == None:
			return
		prev = head
		now = head.next
		while prev != None and now != None:
			prev.next = now.next
			now = None
			prev = prev.next
			if prev != None:
				now = prev.next


class Solution:

	def deleteAlt(self, head):
		current_node = head
		while current_node is not None and current_node.next is not None:
			current_node.next = current_node.next.next
			current_node = current_node.next


class Solution:

	def deleteAlt(self, head):
		curr = head
		while curr is not None:
			if curr.next is not None and curr.next is not None:
				curr.next = curr.next.next
				curr = curr.next
			else:
				break


class Solution:

	def deleteAlt(self, head):
		itr = head
		while itr:
			temp = itr.next
			if temp is not None:
				itr.next = temp.next
				temp = None
			else:
				break
			itr = itr.next


class Solution:

	def deleteAlt(self, head):
		p = head
		cnt = 0
		prev = p
		while p:
			if cnt % 2:
				q = p.next
				prev.next = q
			prev = p
			p = p.next
			cnt += 1


class Solution:

	def deleteAlt(self, head):
		curr = head
		while curr and curr.next:
			tmp = curr.next.next
			curr.next = curr.next.next
			curr = tmp


class Solution:

	def deleteAlt(self, head):
		length = 0
		temp = head
		while temp is not None:
			length += 1
			temp = temp.next
		if length == 1 or length == 2:
			return head.data
		else:
			temp = head
			while temp is not None and temp.next is not None:
				temp.next = temp.next.next
				temp = temp.next
		return head


class Solution:

	def deleteAlt(self, head):
		temp = head
		prev = None
		count = 1
		while temp:
			if temp.next is None:
				break
			else:
				prev = temp
				temp = temp.next
				if count % 2 != 0:
					prev.next = temp.next
				count += 1


class Solution:

	def deleteAlt(self, head):
		i = 1
		cur = head
		while cur.next:
			if i % 2 != 0:
				if cur.next.next:
					cur.next = cur.next.next
					cur = cur.next
					i += 2
				else:
					cur.next = None
		return None


class Solution:

	def deleteAlt(self, head):
		previous = head
		temp = head.next
		while temp:
			previous.next = temp.next
			temp = None
			previous = previous.next
			if previous:
				temp = previous.next


class Solution:

	def deleteAlt(self, node):
		while node:
			if node.next:
				node.next = node.next.next
			node = node.next


class Solution:

	def deleteAlt(self, head):
		itr = head
		c = 0
		while itr != None and itr.next != None:
			itr.next = itr.next.next
			itr = itr.next
		return head


class Solution:

	def deleteAlt(self, head):
		count = 1
		temp = head
		while temp.next != None:
			if temp.next.next == None:
				temp.next = None
				break
			temp.next = temp.next.next
			temp = temp.next
		return head


class Solution:

	def deleteAlt(self, head):
		curr = head
		while curr is not None:
			if curr.next is None:
				break
			temp = curr.next.next
			curr.next.next = None
			curr.next = temp
			curr = curr.next
		return head


class Solution:

	def deleteAlt(self, head):
		cur = head
		while cur and cur.next:
			prev = cur.next
			cur.next = prev.next
			cur = cur.next
		return head


class Solution:

	def deleteAlt(self, head):
		temp = head
		while temp is not None and temp.next is not None:
			temp.next = temp.next.next
			temp = temp.next
		return head


class Solution:

	def deleteAlt(self, head):
		g = head
		while g != None and g.next != None:
			g.next = g.next.next
			g = g.next
		return g


class Solution:

	def deleteAlt(self, head):
		cur = head
		while cur.next != None and cur.next.next != None:
			cur.next = cur.next.next
			cur = cur.next
		cur.next = None
		return cur


class Solution:

	def deleteAlt(self, head):
		dup = head
		while head and head.next:
			head.next = head.next.next
			head = head.next
		return dup


class Solution:

	def deleteAlt(self, head):
		temp = head
		j = 0
		while temp.next:
			if (j + 1) % 2:
				temp.next = temp.next.next
			else:
				temp = temp.next
			j += 1
		return head


class Solution:

	def deleteAlt(self, head):
		if not head:
			return
		fast = head.next
		slow = head
		while fast and slow:
			slow.next = fast.next
			fast = None
			slow = slow.next
			if slow:
				fast = slow.next