We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
nice. I tried a list comprehension (two lines) but it times out. I thought there might be repeats, negating set.
answer = [1 for x in range(len(a)) for y in range(x+1,len(a)) if abs(a[x] - a[y]) == k]
return sum(answer)
Pairs
You are viewing a single comment's thread. Return to all comments →
nice. I tried a list comprehension (two lines) but it times out. I thought there might be repeats, negating set.
answer = [1 for x in range(len(a)) for y in range(x+1,len(a)) if abs(a[x] - a[y]) == k] return sum(answer)