Hackerland Radio Transmitters
- Time : O(nlogn)
- Space : O(1)
1 2 3 4 5 6 7 8 9 10 11 12
| int hackerlandRadioTransmitters(vector<int> x, int k) { sort(begin(x), end(x)); int res = 0, cover = INT_MIN; for(auto& h : x) { if(cover >= h) continue; res++; auto ub = upper_bound(begin(x), end(x), h + k); --ub; cover = *ub + k; } return res; }
|