We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Constraints: The data elements of the linked list argument will always be in non-decreasing order.
The same number should be adjacent, therefore we just need to remove (that is, skip) the adjacent duplicate numbers.
defremoveDuplicates(self,head):#Write your code hereifhead!=Noneandhead.next!=None:cur=headnew_node=curnew_data=cur.datacur=cur.nextwhilecur!=None:# duplicate, skipifcur.data!=new_data:# new value, linked nodes and updatenew_node.next=curnew_node=curnew_data=cur.datacur=cur.nextnew_node.next=Nonereturnhead
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 24: More Linked Lists
You are viewing a single comment's thread. Return to all comments →
Since we know from contrains:
Constraints: The data elements of the linked list argument will always be in non-decreasing order.
The same number should be adjacent, therefore we just need to remove (that is, skip) the adjacent duplicate numbers.