Python/백준

[10816] 숫자카드2

류경혜 2022. 8. 21. 22:30

bisect: 파이썬 내장 이진탐색 모듈 
bisect_left(literable, value): 왼쪽 인덱스 구하기
bisect_right(literable, value): 오른쪽 인덱스 구하기
from bisect import bisect_left, bisect_right
n = int(input())
card = sorted(map(int, input().split()))
m = int(input())
compare = list(map(int, input().split()))


def count_by_range(array, leftValue, rightValue):
    rightIndex = bisect_right(array, rightValue)
    leftIndex = bisect_left(array, leftValue)
    return rightIndex - leftIndex


for i in range(len(compare)):
    print(count_by_range(card, compare[i], compare[i]), end=' ')