原题题目
代码实现(首刷自解)
class Solution {
public:bool judge(vector<int>& position,int diff,int m){
int now_ball = 1,ball_pos = 0;for(int i=1;i<position.size();++i){
if(position[i] - position[ball_pos] >= diff){
++now_ball;ball_pos = i;}if(now_ball >= m) return true;}return false;}int maxDistance(vector<int>& position, int m) {
sort(position.begin(),position.end());int left = 1,right = position.back()-position[0];while(left < right){
int mid = (left + right + 1)/2;if(!judge(position,mid,m)) right = mid-1;else left = mid;}return left;}
};