This commit is contained in:
parent
8a6b22d753
commit
1609c46b28
1 changed files with 20 additions and 0 deletions
20
medium/successful_pairs_of_spells_and_potions.py
Normal file
20
medium/successful_pairs_of_spells_and_potions.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# https://leetcode.com/problems/successful-pairs-of-spells-and-potions
|
||||
|
||||
from typing import List
|
||||
|
||||
class Solution:
|
||||
def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:
|
||||
potions.sort()
|
||||
for i in range(len(spells)):
|
||||
spell = spells[i]
|
||||
left = 0
|
||||
right = len(potions) - 1
|
||||
while left <= right:
|
||||
mid = (left + right) // 2
|
||||
if spell * potions[mid] >= success:
|
||||
right = mid - 1
|
||||
else:
|
||||
left = mid + 1
|
||||
spells[i] = len(potions) - left
|
||||
return spells
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue