Skip to content

Commit ae6c1ec

Browse files
committed
2300: add sol in python
Signed-off-by: ductnn <[email protected]>
1 parent e587e46 commit ae6c1ec

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

leetcode/daily/2300/sol.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https://leetcode.com/problems/successful-pairs-of-spells-and-potions
2+
3+
from bisect import bisect_left
4+
from typing import List
5+
6+
7+
class Solution:
8+
def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:
9+
potions.sort()
10+
return [len(potions) - bisect_left(potions, (success + spell - 1) // spell) for spell in spells]
11+
12+
def bisect_left(self, nums: List[int], target: int) -> int:
13+
left, right = 0, len(nums)
14+
while left < right:
15+
mid = (left + right) // 2
16+
if nums[mid] < target:
17+
left = mid + 1
18+
else:
19+
right = mid
20+
return left
21+
22+
if __name__ == "__main__":
23+
spells = [5, 1, 3]
24+
potions = [1, 2, 3, 4, 5]
25+
success = 7
26+
print(Solution().successfulPairs(spells, potions, success))
27+
print(Solution().bisect_left(potions, success))

0 commit comments

Comments
 (0)