Absolute distinct count in a Linked List | Node of the singly linked list ; Function to insert a node at the beginning of the singly Linked List ; Allocate node ; Insert data ; Point to the head ; Make the new Node the new head ; Function to return the count of distinct absolute values in the linked list ; Create the Head ; Insert nodes
class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = next NEW_LINE DEDENT DEDENT def push ( head_ref , new_data ) : NEW_LINE INDENT new_node = Node ( 0 ) NEW_LINE new_node . data = new_data NEW_LINE new_node . next = ( head_ref ) NEW_LINE ( head_ref ) = new_node NEW_LINE return head_ref NEW_LINE DEDENT def distinctCount ( head_ref1 ) : NEW_LINE INDENT s = set ( ) NEW_LINE ptr1 = head_ref1 NEW_LINE while ( ptr1 != None ) : NEW_LINE INDENT s . add ( abs ( ptr1 . data ) ) NEW_LINE ptr1 = ptr1 . next NEW_LINE DEDENT return len ( s ) NEW_LINE DEDENT head1 = None NEW_LINE head1 = push ( head1 , - 1 ) NEW_LINE head1 = push ( head1 , - 2 ) NEW_LINE head1 = push ( head1 , 0 ) NEW_LINE head1 = push ( head1 , 4 ) NEW_LINE head1 = push ( head1 , 5 ) NEW_LINE head1 = push ( head1 , 8 ) NEW_LINE ans = distinctCount ( head1 ) NEW_LINE print ( ans ) NEW_LINE