๐ก Python 3
H-Index [Link]
ํจ์จ์ฑ ์ ๋ก ๋ด ์ฝ๋
def solution(citations):
answer = 0
citations.sort()
for i in range(max(citations)+1):
count = 0
for c in citations:
if i <= c: count += 1
if count >= i and len(citations)-count <= i: answer = max(answer, i)
return answer
๋๋ฐ !! ์์ ๊น๋ํ๋ฉด์ ๋ด์ฅ ํจ์๋ฅผ ์ ํ์ฉํ ์ฝ๋
def solution(citations):
citations.sort(reverse=True)
answer = max(map(min, enumerate(citations, start=1)))
return answer
sort
๋ก ๊ฐ์ฅ ํฐ ๊ฐ๋ถํฐ ์์ ๊ฐ์ผ๋ก ์ ๋ ฌ
enumerate
๋ก (index, value)
ํํ๋ก ๋ฌถ์
์ต๋๊ฐ(start = 1)๋ถํฐ ๊ฐ value์ ๋ํด ์ต์๊ฐ value์ ๊ฐ์ min
์ผ๋ก ์ถ์ถ
์ด ์ถ์ถ๋ ๊ฐ์ enumerate
๊ฐ ๋๋๋ citations ๋ฆฌ์คํธ์ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ฐฏ์ ๋ฐํ
map
์ผ๋ก ๋ฌถ์ผ๋ฉด ํ value์ ์
์ฅ์์ ๋ณด๋ ์ต์๊ฐ value์ ์งํฉ, ์ฆ h๊ฐ๋ค์ ์งํฉ ๋ฐํ
h๊ฐ์ค ์ต๋๊ฐ์ max
๋ก ๋ฝ์์ ์ถ๋ ฅ