Created
August 9, 2020 18:46
-
-
Save Svastikkka/e90442bedd6bf1f31d5aaf18f2e2229f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Eliminate duplicates from LL