leetcode

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

1333.cpp (850B)


      1 class Solution {
      2   public:
      3     vector<int> filterRestaurants(const vector<vector<int>> &restaurants, int veganFriendly, int maxPrice,
      4                                   int maxDistance) const {
      5         vector<int> res;
      6         for (int i = 0; i < restaurants.size(); i++) {
      7             if (restaurants[i][3] > maxPrice || restaurants[i][4] > maxDistance) continue;
      8             if (veganFriendly && !restaurants[i][2]) continue;
      9             res.push_back(i);
     10         }
     11         sort(begin(res), end(res), [&](int a, int b) {
     12             return restaurants[a][1] != restaurants[b][1] ? restaurants[a][1] > restaurants[b][1]
     13                                                           : restaurants[a][0] > restaurants[b][0];
     14         });
     15         for (int i = 0; i < res.size(); i++)
     16             res[i] = restaurants[res[i]][0];
     17         return res;
     18     }
     19 };