首页 > 其他 > 详细

leetcode1333

时间:2020-01-26 15:02:05      阅读:64      评论:0      收藏:0      [点我收藏+]
 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

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

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

leetcode1333

原文:https://www.cnblogs.com/asenyang/p/12234190.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!