Python Day 24: More Linked Lists

A Node class is provided for you in the editor. A Node object has an integer data field, data, and a Node instance pointer, next, pointing to another node (i.e.: the next node in a list).

A removeDuplicates function is declared in your editor, which takes a pointer to the head node of a linked list as a parameter. Complete removeDuplicates so that it deletes any duplicate nodes from the list and returns the head of the updated list.

Note: The head+ pointer may be null, indicating that the list is empty. Be sure to reset your next pointer when performing deletions to avoid breaking the list.

  1. class Node:
  2. def __init__(self,data):
  3. = data
  4. = None
  5. class Solution:
  6. def insert(self,head,data):
  7. p = Node(data)
  8. if head==None:
  9. head=p
  10. elif
  12. else:
  13. start=head
  14. while(!=None):
  17. return head
  18. def display(self,head):
  19. current = head
  20. while current:
  21. print(,end=' ')
  22. current =
  23. def removeDuplicates(self,head):
  24. #Write your code here
  25. node = head
  26. while node:
  27. if
  28. if ==
  29. =
  30. continue
  31. node =
  32. return head
  33. mylist= Solution()
  34. T=int(input())
  35. head=None
  36. for i in range(T):
  37. data=int(input())
  38. head=mylist.insert(head,data)
  39. head=mylist.removeDuplicates(head)
  40. mylist.display(head);
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

donate a cup of tea :)

Join Our Facebook Group

Share this solution is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube