LeetCode 2300. Successful Pairs of Spells and Potions in F#
URL
Successful Pairs of Spells and Potions - LeetCode
Code
let successfulPairs (spells: int list) (potions: int list) (success: int64) : int list =
let rec lowerBound left right spell (vals: int[]) =
if left >= right then
left
else
let mid = left + (right - left) / 2
if int64 (spell * vals.[mid]) < success then
lowerBound (mid + 1) right spell vals
else
lowerBound left mid spell vals
let potions = potions |> List.sort |> List.toArray
let len = potions.Length
spells
|> List.map (fun spell ->
let pos = lowerBound 0 len spell potions
len - pos)
Comments
Join the discussionNo comments yet. Be the first to comment.