C++ 8 lines solution


  • 0
        int findRadius(vector<int>& houses, vector<int>& heaters) {
            sort(houses.begin(),houses.end());
            sort(heaters.begin(),heaters.end());
            int i=0,rad=0;
            for(int x:houses){
                while(i<heaters.size()-1&&heaters[i]+heaters[i+1]<=x*2) i++;
                rad=max(rad,abs(heaters[i]-x));
            }
            return rad;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.