python-for-coding-test icon indicating copy to clipboard operation
python-for-coding-test copied to clipboard

Q5. 볼링공 고르기 질문 드립니다!

Open minha62 opened this issue 3 years ago • 1 comments

n, m = map(int, input().split())
k = list(map(int, input().split()))
result = 0

for i in range(n):
    for j in range(i, n):
        if k[i] != k[j]:
            result += 1

print(result)

저는 이런 식으로 풀었는데 이렇게 풀어도 괜찮을까요?

책에 나와있는 답안과 많이 다르게 푼 것 같아서 질문 드립니다!

minha62 avatar Mar 12 '22 13:03 minha62

출력에는 문제가 없으나 시간복잡도 O(n^2)을 가져서 책에 나온 풀이보단 효율이 떨어집니다.

Yooncoding avatar May 12 '22 10:05 Yooncoding