python dict 时间复杂度为O(1), python 也支持位运算
a=[1,2,3,4,5,6,7,8,9,10,11,12,15,18,90,25]
b=[5,6,8,9,3,2,5,8,46,8,214,6]
a.sort()
b.sort()
print a
print b
def __main__():
t=time()
c=[v for v in a if v in b]
print c
print time()-t
def __intersection__():
t=time()
la = a.__len__()
lb = b.__len__()
j = 0
for i in xrange(lb):
if j > la-1:
break
while j <= la-1:
if b[i] > a[j]:
j +=1
else:
if b[i] == a[j]:
print b[i]
break
print time()-t
def __union__():
t=time()
la = a.__len__()
lb = b.__len__()
j = 0
for i in xrange(lb):
while j <= la-1:
if b[i] > a[j]:
print a[j]
else:
if b[i] != a[j]:
print b[i]
break
j += 1
if j > la-1:#need print b[i<lb]
print b[i]
pass
print time()-t
def __unsort_union__():
t=time()
la = a.__len__()
lb = b.__len__()
hash = 0x0
j = 0
for i in xrange(lb):
hash |= 1<<b[i]
for i in xrange(la):
if not hash&(1<<a[i]):
b.append(a[i])
print b
print time()-t