力扣 中等 2300.咒语和药水的成功对数
题目介绍
解法
class Solution {
public int[] successfulPairs(int[] spells, int[] potions, long success){
Arrays.sort(potions);
int n = spells.length, m = potions.length;
int[] pairs = new int[n];
for (int i = 0; i < n; i++) {
int left = 0, right = m - 1;
long factor = spells[i];
while (left <= right) {
int mid = left + (right - left) / 2;
if ((long) potions[mid] * factor < success) {
left = mid + 1;
} else {
right = mid - 1;
}
}
pairs[i] = m - left;
}
return pairs;
}
}
原文地址:https://blog.csdn.net/qq_51352130/article/details/142379261
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!