我的博客

leetcode 周赛 173 5320. 餐厅过滤器 filter restaurants by vegan friendly price and distance

目录

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

简单

1
2
3
4
5
6
7
8
9
10
class Solution:
def filterRestaurants(self, restaurants: List[List[int]], veganFriendly: int, maxPrice: int, maxDistance: int) -> List[int]:
# restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]
ans = []
for r in restaurants:
if veganFriendly == 1 and r[2] == 0: continue
if r[3] > maxPrice or r[4] > maxDistance: continue
ans.append(r)
ans.sort(key=lambda x: x[1]*1e5+x[0], reverse=True)
return [x[0] for x in ans]

评论无需登录,可以匿名,欢迎评论!