Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- double minmaxGasDist(vector<int>& stations, int k) {
- double low = 0, high = 1e8, mid;
- while(high - low > 1e-6){
- double mid = (low+high)/2.0;
- if(check(mid, stations, k))
- high = mid;
- else
- low = mid;
- }
- return low;
- }
- bool check(double dist, vector<int> stations, int k){
- int stops = 0;
- for(int i=0; i<stations.size()-1; i++)
- stops += int(double(stations[i+1]-stations[i])/dist);
- return stops <= k;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement