Python2 2751-수 정렬하기 2 (python) """ 1. 내가 작성한 코드 (계수 정렬 알고리즘 사용) """ """ 이점: 메모리를 적게 사용함 """ import sys n = int(sys.stdin.readline()) MAX = 1_000_000 negatives = [0 for _ in range(MAX + 1)] positives = [0 for _ in range(MAX + 1)] for _ in range(n): number = int(sys.stdin.readline()) if number >= 0: positives[number] += 1 else: negatives[-number] += 1 for x in range(MAX, -1, -1): if negatives[x] >= 1: print(-x) for x in range(M.. 2020. 10. 12. 4195-친구 네트워크 (python) def find(x): if x != parents[x]: parents[x] = find(parents[x]) return parents[x] def union(x, y): root1 = find(x) root2 = find(y) if root1 != root2: parents[root2] = root1 numbers[root1] += numbers[root2] tc = int(input()) for _ in range(tc): parents = dict() numbers = dict() f = int(input()) for _ in range(f): x, y = input().split() if x not in parents: parents[x] = x numbers[x] = 1 if y not in.. 2020. 10. 12. 이전 1 다음