Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for singly-linked list.
- * struct ListNode {
- * int val;
- * ListNode *next;
- * ListNode(int x) : val(x), next(NULL) {}
- * };
- */
- class Solution {
- public:
- int numComponents(ListNode* head, vector<int>& G) {
- // save g in set
- unordered_set<int> s(G.begin(), G.end());
- int result = 0;
- if(!head)
- return result;
- auto p = head;
- auto q = head->next;
- while(q){
- if(s.find(q->val) != s.end() && s.find(p->val) != s.end()){
- result += 1;
- cout<<q->val<<" "<<p->val<<endl;
- }
- p = q;
- q = q->next;
- }
- return G.size() - result;
- }
- };
Add Comment
Please, Sign In to add comment