6096 20220611夜周赛第二题
https://leetcode.cn/problems/successful-pairs-of-spells-and-potions/
class Solution:
def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:
# potions.sort()
# return [len(potions) - bisect_left(potions, (success + x - 1) // x) for x in spells]
potions.sort()
array = []
def binarySearch(array: List[int], k: int) -> int:
left = 0
right = len(array) - 1
while left <= right:
mid = (left + right) // 2
if array[mid] == k:
return mid
elif array[mid] > k:
left = mid + 1
else:
right = mid - 1
for i in spells:
array.append(len(potions) - binarySearch(potions, math.ceil(success // i)))
return array
mission
- 学习库函数 bisect.left()的参数以及用法,将其入库
- https://docs.python.org/zh-cn/3.10/library/bisect.html
- 搞懂 灵茶山乐府版本 x - 1的原因