ALDS_4_B – 二分探索
n = int(input())
s = list(map(int,input().split()))
q = int(input())
t = list(map(int,input().split()))
def search(x):
l = 0
r = n-1
while l <= r:
mid = (l+r)//2
if s[mid] == x:
return 1
elif s[mid] < x:
l = mid + 1
else:
r = mid -1
return 0
ans = 0
for i in t:
ans += search(i)
print(ans)
コメント