思路0:
数组变为有序,依次放置,小球。最先两个球,放在首尾。
然后用二分查找方式,查找中间小球放置的位置。中间位置查找标准为,距离首部或者尾部的球,引力最大,找到这个引力最大值的位置,就是这个小球的位置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution:



def maxDistance(self, position: List[int], m: int) -> int:
position.sort()
n = len(position)
left,right = 0,n-1

def bitsect(self,left,right):
left,right = 0,n-1
while left<right:
mid = (left+right)//2
if (position[mid]-position[left]) <(position[right]-position[mid]):
right = mid
else:
left = mid
return left

if m ==1:
return 0
if m ==2:
return positon[right]-positon[left]

if m==3:
self.bitsect(new_left,new_right)