Created
February 22, 2018 14:54
-
-
Save s4553711/258601e9f5fd2d2bdd0892e787b4ff93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int findRadius(vector<int>& houses, vector<int>& heaters) { | |
if (heaters.size() == 0) return 0; | |
sort(houses.begin(), houses.end()); | |
sort(heaters.begin(), heaters.end()); | |
int radius = 0; | |
int index = 0; | |
for(int i = 0; i < houses.size(); i++) { | |
while(index + 1 < heaters.size() && abs(heaters[index+1] - houses[i]) <= abs(heaters[index] - houses[i])) { | |
index++; | |
} | |
radius = max(radius, abs(heaters[index] - houses[i])); | |
} | |
return radius; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment