leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0817.cpp (513B)


      1 class Solution {
      2   public:
      3     int numComponents(ListNode *head, vector<int> &nums) {
      4         static int seen[10001];
      5         memset(seen, 0x00, sizeof(seen));
      6         for (const int n : nums)
      7             seen[n] = true;
      8 
      9         int res = 0, started = 0;
     10         for (const ListNode *crnt = head; crnt; crnt = crnt->next) {
     11             if (!seen[crnt->val])
     12                 res += started, started = 0;
     13             else
     14                 started = 1;
     15         }
     16         res += started;
     17         return res;
     18     }
     19 };