[Algorithm] [백준] 1453 (Feat. 집합(set))

myeonji·2022년 2월 5일
0

Algorithm

목록 보기
33/89

> 집합(set)

  • 가변 객체는 집합의 항목이 될 수 없다.
  • {} 를 사용한다.
  • 중복이 없다.
  • 순서가 없다.
  • 빈 집합을 만들 때는 set() 함수를 사용한다.

n = int(input())
li = [0] * n

seat = list(map(int, input().split()))

cnt = 0
for i in range(n):
    if seat[i] in li:
        cnt += 1
    else:
        li[i] = seat[i]

print(cnt)

for문을 쓰지 않고도 풀 수 있다. 집합(set)을 사용해서 중복을 제거하면 된다.

n = int(input())
seat = list(map(int, input().split()))

print(n - len(set(seat)))

0개의 댓글