def dupbit(arr):
bitmap =0
dup =[]
for num in arr:
bit= 1<<(num-1)
if bit & bitmap:
dup.append(num)
else:
bitmap |=bit
return dup
array = [1,2,3,4,5,2,4,5,2,4,8]
print(dupbit(array))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter