## LeetCode-Python-5320. 餐厅过滤器（数组 + 排序）

```输入：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

```

```输入：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

```

```输入：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

```

• `1 <= restaurants.length <= 10^4`
• `restaurants[i].length == 5`
• `1 <= idi, ratingi, pricei, distancei <= 10^5`
• `1 <= maxPrice, maxDistance <= 10^5`
• `veganFriendlyi` 和 `veganFriendly` 的值为 0 或 1 。
• 所有 `idi` 各不相同。

``````class Solution(object):
def filterRestaurants(self, restaurants, veganFriendly, maxPrice, maxDistance):
"""
:type restaurants: List[List[int]]
:type veganFriendly: int
:type maxPrice: int
:type maxDistance: int
:rtype: List[int]
"""
if not restaurants:
return []

res = []
for i, rating, vF, mP, mD in restaurants:
if not veganFriendly or (vF and veganFriendly):
if mP <= maxPrice and mD <= maxDistance:
res.append([i, rating])

return [i for i, rating in sorted(res, key = lambda x:(x[1], x[0]), reverse = True)]``````