Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Cracking Coding Interview - Remove Dups Linked List

def remove_dups(head_node)
    unique_values = {}
    current_node = head_node
    prev_node = nil
    while current_node.next != nil
        if unique_values.key?(current_node.value)
            prev_node.next = current_node.next
        else
            unique_values[current_node.value] = true
            prev_node = current_node
        end
        current_node = current_node.next
    end
    current_node
end

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.