其他分享
首页 > 其他分享> > leetcode1333

leetcode1333

作者:互联网

 1 class Solution:
 2     def filterRestaurants(self, restaurants: 'List[List[int]]', veganFriendly: int, maxPrice: int, maxDistance: int) -> 'List[int]':
 3         n = len(restaurants)
 4         satisfied = []
 5         for i in range(n):
 6             cur = restaurants[i]
 7             if veganFriendly == 1:
 8                 if cur[2] == 1 and cur[3] <= maxPrice and cur[4] <= maxDistance:
 9                     satisfied.append([cur[0],cur[1]])
10             else:
11                 if cur[3] <= maxPrice and cur[4] <= maxDistance:
12                     satisfied.append([cur[0],cur[1]])
13         satisfied = sorted(satisfied,key=lambda x:[-x[1],-x[0]])
14         result = []
15         for s in satisfied:
16             result.append(s[0])
17         return result

算法思路:多维数组,多条件排序。

先取出所有符合条件的元素,再按照两个条件排序。

标签:cur,int,veganFriendly,List,leetcode1333,排序,restaurants
来源: https://www.cnblogs.com/asenyang/p/12234190.html