leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0817.cpp (513B)
0 class Solution { 1 public: 2 int numComponents(ListNode *head, vector<int> &nums) { 3 static int seen[10001]; 4 memset(seen, 0x00, sizeof(seen)); 5 for (const int n : nums) 6 seen[n] = true; 7 8 int res = 0, started = 0; 9 for (const ListNode *crnt = head; crnt; crnt = crnt->next) { 10 if (!seen[crnt->val]) 11 res += started, started = 0; 12 else 13 started = 1; 14 } 15 res += started; 16 return res; 17 } 18 };