很简单的中等题,先排序再二分查找即可
class Solution:
def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:
potions.sort()
m = len(potions)
ans = []
for sp in spells:
t = success / sp
ans.append(m - bisect_left(potions, t))
return ans
循环填充列表答案的代码都可以一行完成