Skip to content

Latest commit

 

History

History
31 lines (22 loc) · 1.05 KB

File metadata and controls

31 lines (22 loc) · 1.05 KB
 long long MOD=1000000007;
        long long unsigned int decimalValue(Node *head)
        {
           // Your Code Here
           long long unsigned int ans =0;
           Node* start=head;
           
           while(start!=NULL)
           {
               ans=(ans*2 + start->data)%MOD;
               start=start->next;
           }
           
           return ans;
        }

here as we dont know the size of linked list, so, each moment when we are on node , we are asssuming that it is final/last node, then we the next node is present we simply multiply 2 with the previous node alt text

Note

  1. Unable to for the approach in which we push the data in vector then, through travsling simply ans can calculated, HERE VECTOR IS UNDEFINED

  2. cannot use the pow method

thats why reversing of the linked list or calculating of size is that possible