Skip to content

Instantly share code, notes, and snippets.

@Svastikkka
Created August 9, 2020 18:46
Show Gist options
  • Save Svastikkka/e90442bedd6bf1f31d5aaf18f2e2229f to your computer and use it in GitHub Desktop.
Save Svastikkka/e90442bedd6bf1f31d5aaf18f2e2229f to your computer and use it in GitHub Desktop.
class Node:
def __init__(self,data):
self.data=data
self.next=None
def LinkedList(arr):
head=None
tail=None
if len(arr)<1:
return
else:
for i in arr:
if i ==-1:
break
NewNode=Node(i)
if head is None:
head=NewNode
tail=NewNode
else:
tail.next=NewNode
tail=NewNode
return head
def printLL(head):
while head is not None:
print(head.data,end=" ")
head=head.next
# This function removes duplicates from list
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
t=int(input())
for i in range(t):
arr=list(map(int,input().split()))
printLL(removeDuplicates(LinkedList(arr)))
@Svastikkka
Copy link
Author

Eliminate duplicates from LL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment