leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0475.cpp (636B)


0 class Solution {
1 public:
2 int findRadius(vector<int> &houses, vector<int> &heaters) const {
3 sort(begin(heaters), end(heaters));
4 sort(begin(houses), end(houses));
6 int res = 0, crnt;
7 const int n = size(houses);
8 const int m = size(heaters);
9 for (int i = 0, j = 0; i < n; i++) {
10 while (j < m && houses[i] >= heaters[j])
11 j++;
13 int crnt = INT_MAX;
15 if (j > 0) crnt = houses[i] - heaters[j - 1];
16 if (j != m) crnt = min(crnt, heaters[j] - houses[i]);
18 res = max(res, crnt);
19 }
21 return res;
22 }
23 };