-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_3_pointers.py
More file actions
33 lines (33 loc) · 899 Bytes
/
Array_3_pointers.py
File metadata and controls
33 lines (33 loc) · 899 Bytes
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
30
31
32
33
class Solution:
# @param A : tuple of integers
# @param B : tuple of integers
# @param C : tuple of integers
# @return an integer
def minimize(self, A, B, C):
a = len(A)
b = len(B)
c = len(C)
i = j = k =0
ans = 2**31 -1
while i<a and j<b and k<c:
d1 = abs(A[i]-B[j])
d2 = abs(B[j]-C[k])
d3 = abs(C[k]-A[i])
tmp = max(d1,d2,d3)
ans = min(ans,tmp)
if tmp==d1:
if A[i]==min(A[i],B[j]):
i+=1
else:
j+=1
elif tmp==d2:
if B[j]==min(B[j],C[k]):
j+=1
else:
k+=1
else:
if C[k]==min(C[k],A[i]):
k+=1
else:
i+=1
return ans