기억은 짧고 기록은 길다
[프로그래머스/Programmers] H-index - Python 본문
Link
코딩테스트 연습 - K번째수
[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]
programmers.co.kr
Solution
def solution(citations):
citations = sorted(citations, reverse=True)
answer = len(citations)
while True:
count = 0
for i in range(len(citations)):
if citations[i] >= answer:
count += 1
if count < answer:
answer -= 1
else:
return answer
🔑 key point:
1. citations = sorted(citations, reverse=True)
2. if count < answer: answer -= 1
Other Solution
def solution(citations):
citations.sort(reverse=True)
answer = max(map(min, enumerate(citations, start=1)))
return answer
🔑 key point: answer = max(map(min, enumerate(citations, start=1)))
def solution(citations):
citations = sorted(citations)
l = len(citations)
for i in range(l):
if citations[i] >= l - i:
return l - i
return 0
🔑 key point: len(citations) - i
'CodingTest > programmers' 카테고리의 다른 글
[프로그래머스/Programmers] 가장 큰 정사각형 찾기 - Python (0) | 2021.09.09 |
---|---|
[프로그래머스/Programmers] N개의 최소공배수 - Python (0) | 2021.09.09 |
[프로그래머스/Programmers] 행렬의 곱셈 - Python (0) | 2021.09.08 |
[프로그래머스/Programmers] 올바른 괄호 - Python (0) | 2021.09.08 |
[프로그래머스/Programmers] 소수 찾기 _2- Python (0) | 2021.09.08 |
Comments