leetcode

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

3159.cpp (430B)


      1 class Solution {
      2   public:
      3     vector<int> occurrencesOfElement(vector<int> &nums, vector<int> &queries, int x) {
      4         static int count[100001];
      5         int sz = 1;
      6 
      7         for (int i = 0; i < size(nums); i++) {
      8             if (nums[i] != x) continue;
      9             count[sz++] = i;
     10         }
     11 
     12         for (auto &query : queries) {
     13             query = query < sz ? count[query] : -1;
     14         }
     15 
     16         return queries;
     17     }
     18 };