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

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

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

posted on 2020-01-26 14:41  Sempron2800+  阅读(136)  评论(0编辑  收藏  举报