Sort by

recency

|

723 Discussions

|

  • + 0 comments

    Python 3. My janky cringy solution

    def removeDuplicates(self,head):
            cur= head
            while cur and cur.next:
                while cur.next and cur.data == cur.next.data:
                    cur.next = cur.next.next
                cur = cur.next
    
        return head
    
  • + 0 comments
    public static Node removeDuplicates(Node head) {
      //Write your code here
        Node start = head;
        while(head != null && head.next != null) {
            if (head.data == head.next.data) {
                head.next = head.next.next;
            } else {
                head = head.next;
            }
        }
        return start;
    }
    
  • + 0 comments

    C#

      public static Node removeDuplicates(Node head){
        
        var current = head;
        
        while(current.next is not null)
        {
            if(current.data == current.next.data)
            {
                current.next = current.next.next;
            }
            else current = current.next;
        }
        
        return head;
      }
    
  • + 0 comments

    Python3 solution

        def removeDuplicates(self,head):
            slow = fast = head
            while fast.next:
                fast = fast.next
                
                if fast.data == slow.data:
                    continue
                
                slow.next = slow = fast
            
            slow.next = None        
            return head
    
  • + 0 comments

    Simplest Py3 solution:

    def removeDuplicates(self,head):
            if head is None:
                return head
                
            start = head
            curr = head
            
            while curr.next is not None:
                if curr.next.data == curr.data:
                    curr.next = curr.next.next
                else:
                    curr = curr.next
                    
            return start