[Solved] Python Code - Let me know if you better code


#1
for i in range(len(A)-1) :
    for j in range(i+1, len(A)) :
        if abs(A[i]-A[j]) == B :
            return 1
return 0

#2

This is better beacause this run less iterations
def diffPossible(self,A,B):
for i in range(len(A)):
for j in range(len(A)-1, -1, -1):
if(i!=j and A[j]-A[i]== B):
return 1
elif( A[j]-A[i] < B):
break
return 0


#3
int i = 0 ,j =(A.size()-1)/2;
while(i<=j && j<A.size()){
    if(A[j] - A[i] == B && i!=j) return 1;
    else if((A[j]-A[i]) > B)i++;
    
    else j++;

return 0;