mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 18:07:32 +01:00
26 lines
691 B
C#
26 lines
691 B
C#
|
public class Solution {
|
||
|
public int[] SuccessfulPairs(int[] spells, int[] potions, long success) {
|
||
|
int getSuccessful(long strength) {
|
||
|
var (left, right) = (0, potions.Length);
|
||
|
|
||
|
while (left < right) {
|
||
|
var mid = (left + right) / 2;
|
||
|
if (strength * potions[mid] >= success) {
|
||
|
right = mid;
|
||
|
} else {
|
||
|
left = mid + 1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return potions.Length - left;
|
||
|
}
|
||
|
|
||
|
// Ensort potions to allow bisection.
|
||
|
Array.Sort(potions);
|
||
|
|
||
|
return spells
|
||
|
.Select(s => getSuccessful(s))
|
||
|
.ToArray();
|
||
|
}
|
||
|
}
|