zoukankan      html  css  js  c++  java
  • 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

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

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

  • 相关阅读:
    《人月神话》阅读笔记3
    团队冲刺0110
    团队冲刺0109
    团队冲刺0108
    团队冲刺0107
    团队冲刺0106
    团队冲刺0105
    团队冲刺010304
    团队冲刺0102
    团队冲刺0101
  • 原文地址:https://www.cnblogs.com/asenyang/p/12234190.html
Copyright © 2011-2022 走看看