지나가던 개발자
[Python] 백준 10815번(숫자 카드) 문제 풀이 본문
def binary_search(nums, target):
    left, right = 0, len(nums)-1
    while left <= right:
        mid = (left+right) // 2
        if nums[mid] < target:
            left = mid + 1
        elif nums[mid] > target:
            right = mid - 1
        else:
            return 1
    return 0
input()
have = sorted(list(map(int, input().split(" "))))
input()
cards = list(map(int, input().split(" ")))
for i in cards:
    print(binary_search(have, i), end=" ")
이분 탐색 알고리즘을 사용했다.
'PS > Python' 카테고리의 다른 글
| [Python] 백준 1357번(뒤집힌 덧셈) 문제 풀이 (0) | 2022.10.21 | 
|---|---|
| [Python] 백준 8611번(팰린드롬 숫자) 문제 풀이 (0) | 2022.10.20 | 
| [Python] 백준 2693번(N번째 큰 수) 문제 풀이 (0) | 2022.10.19 | 
| [Python] 백준 8595번(히든 넘버) 문제 풀이 (0) | 2022.10.19 | 
| [Python] 백준 2145번(숫자 놀이) 문제 풀이 (0) | 2022.10.18 | 
			  Comments
			
		
	
               
           
					
					
					
					
					
					
				