Leetcode 475. 供暖器 (二分枚举半径大小)
class Solution {
public:
int findRadius(vector
int n = houses.size(), m = heaters.size();
sort(houses.begin(), houses.end());
sort(heaters.begin(), heaters.end());
auto check = [&](int mid) {
int i = 0, j = 0;
while (i < n) {
if (houses[i] >= heaters[j] - mid && houses[i] <= heaters[j] + mid) i++;
else {
j++;
共有 0 条评论