<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      [LeetCode] 1333. Filter Restaurants by Vegan-Friendly, Price and Distance 餐廳過濾器


      Given the array restaurants where  restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]. You have to filter the restaurants using three filters.

      The veganFriendly filter will be either true (meaning you should only include restaurants with veganFriendlyi set to true) or false (meaning you can include any restaurant). In addition, you have the filters maxPrice and maxDistance which are the maximum value for price and distance of restaurants you should consider respectively.

      Return the array of restaurant IDs after filtering, ordered by rating from highest to lowest. For restaurants with the same rating, order them by id from highest to lowest. For simplicity veganFriendlyi and veganFriendly take value 1 when it is true, and 0 when it is false.

      Example 1:

      Input: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10
      Output: [3,1,5]
      Explanation: The restaurants are:
      Restaurant 1 [id=1, rating=4, veganFriendly=1, price=40, distance=10]
      Restaurant 2 [id=2, rating=8, veganFriendly=0, price=50, distance=5]
      Restaurant 3 [id=3, rating=8, veganFriendly=1, price=30, distance=4]
      Restaurant 4 [id=4, rating=10, veganFriendly=0, price=10, distance=3]
      Restaurant 5 [id=5, rating=1, veganFriendly=1, price=15, distance=1]
      After filter restaurants with veganFriendly = 1, maxPrice = 50 and maxDistance = 10 we have restaurant 3, restaurant 1 and restaurant 5 (ordered by rating from highest to lowest).

      Example 2:

      Input: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 50, maxDistance = 10
      Output: [4,3,2,1,5]
      Explanation: The restaurants are the same as in example 1, but in this case the filter veganFriendly = 0, therefore all restaurants are considered.

      Example 3:

      Input: restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 30, maxDistance = 3
      Output: [4,5]

      Constraints:

      • 1 <= restaurants.length <= 10^4
      • restaurants[i].length == 5
      • 1 <= idi, ratingi, pricei, distancei <= 10^5
      • 1 <= maxPrice, maxDistance <= 10^5
      • veganFriendlyi and veganFriendly are 0 or 1.
      • All idi are distinct.

      這道題給了一個餐館數組,每個餐館包括一系列信息,id,rating,veganFriendly,price,distance。現在給了一些搜索條件,比如是否素食友好,最大價格,最大距離,然后返回符合要求的餐館。這其實就是類似 Yelp 的功能啊,這里的素食友好的條件需要特別注意一下,即素食主義者不能去非素食餐館,而非素食主義者可以去素食餐館,所以不能簡單的對比 veganFriendly。所以當餐館的 veganFriendly 是1,給定的 veganFriendly 是0的話,就不能選擇該餐館。那么取個反,當餐館的 veganFriendly 為1,或者給定的 veganFriendly 為0時可以選餐館,另外餐館的價格要小于等于最大價格,且餐館的距離要小于等于最大距離,將符合要求的餐館選出來放到一個新的數組中。之后就是給這個數組排序,排序的方法就是若 rating 不相等,把大的排前面,若 rating 相等,把 Id 大的放前面即可,參見代碼如下:


      class Solution {
      public:
          vector<int> filterRestaurants(vector<vector<int>>& restaurants, int veganFriendly, int maxPrice, int maxDistance) {
              vector<int> res;
              vector<vector<int>> filtered;
              for (auto r : restaurants) {
                  if ((r[2] != 0 || veganFriendly != 1) && r[3] <= maxPrice && r[4] <= maxDistance) {
                      filtered.push_back(r);
                  }
              }
              sort(filtered.begin(), filtered.end(), [](vector<int>& a, vector<int>& b) {
                  return (a[1] != b[1]) ? (a[1] > b[1]) : (a[0] > b[0]);
              });
              for (auto r : filtered) {
                  res.push_back(r[0]);
              }
              return res;
          }
      };
      

      Github 同步地址:

      https://github.com/grandyang/leetcode/issues/1333


      參考資料:

      https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/

      https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/solutions/490344/java-one-liner/

      https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/solutions/492399/c-short-solution/


      LeetCode All in One 題目講解匯總(持續更新中...)

      posted @ 2023-02-27 09:15  Grandyang  閱讀(159)  評論(0)    收藏  舉報
      Fork me on GitHub
      主站蜘蛛池模板: 国产AV福利第一精品| 久久人妻无码一区二区三区av| 亚洲日韩欧美一区二区三区在线| 日韩女同在线二区三区| 亚洲香蕉伊综合在人在线| 美乳丰满人妻无码视频| 色老头亚洲成人免费影院| 亚洲国产欧美一区二区好看电影| 成年无码av片在线蜜芽| 免费高清特级毛片A片| 国产色无码专区在线观看| 宅男噜噜噜66网站高清| 国产精品美女久久久久久麻豆| 欧美白妞大战非洲大炮| 欧洲免费一区二区三区视频| 精品少妇av蜜臀av| 人妻无码中文字幕| A男人的天堂久久A毛片| 成av免费大片黄在线观看| 国产成人一区二区三区视频免费| 免费无码va一区二区三区| 18禁网站免费无遮挡无码中文 | 亚洲一区中文字幕人妻| 国产美女免费永久无遮挡| 国产一区二区三区色老头| 精品无码一区二区三区电影| 9色国产深夜内射| 巢湖市| 亚洲精品无码高潮喷水A| 亚洲人成色99999在线观看| 好男人社区影视在线WWW| 国产成人精品一区二区三区无码| 亚洲中文字幕一区二区| 成人午夜伦理在线观看| 在线播放亚洲人成电影| 岛国岛国免费v片在线观看| 国产精品最新免费视频| 国产亚洲人成网站观看| 国产精品二区中文字幕| 亚洲欧美日韩精品久久亚洲区| 国产精品综合在线免费看|