leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1333.cpp (850B)
0 class Solution { 1 public: 2 vector<int> filterRestaurants(const vector<vector<int>> &restaurants, int veganFriendly, int maxPrice, 3 int maxDistance) const { 4 vector<int> res; 5 for (int i = 0; i < restaurants.size(); i++) { 6 if (restaurants[i][3] > maxPrice || restaurants[i][4] > maxDistance) continue; 7 if (veganFriendly && !restaurants[i][2]) continue; 8 res.push_back(i); 9 } 10 sort(begin(res), end(res), [&](int a, int b) { 11 return restaurants[a][1] != restaurants[b][1] ? restaurants[a][1] > restaurants[b][1] 12 : restaurants[a][0] > restaurants[b][0]; 13 }); 14 for (int i = 0; i < res.size(); i++) 15 res[i] = restaurants[res[i]][0]; 16 return res; 17 } 18 };