MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Solution

Class Solution

LeetCode_problems/Linked List Components/solution.cpp:52–71  ·  view source on GitHub ↗

* Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */

Source from the content-addressed store, hash-verified

50 * };
51 */
52class Solution {
53public:
54 int numComponents(ListNode* head, vector<int>& G) {
55 unordered_set<int> s(G.begin(),G.end());
56 ListNode* temp=head;
57 int c=0;
58 while(temp){
59 if(s.find(temp->val)!=s.end()){
60 c++;
61 while(temp and s.find(temp->val)!=s.end())
62 temp=temp->next;
63 continue;
64 }
65 temp=temp->next;
66 }
67 return c;
68
69
70 }
71};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected