[ํ๋ก๊ทธ๋๋จธ์ค][Python] H-index
๋ฌธ์ ์ค๋ช
H-Index๋ ๊ณผํ์์ ์์ฐ์ฑ๊ณผ ์ํฅ๋ ฅ์ ๋ํ๋ด๋ ์งํ์ ๋๋ค. ์ด๋ ๊ณผํ์์ H-Index๋ฅผ ๋ํ๋ด๋ ๊ฐ์ธ h๋ฅผ ๊ตฌํ๋ ค๊ณ ํฉ๋๋ค. ์ํค๋ฐฑ๊ณผ1์ ๋ฐ๋ฅด๋ฉด, H-Index๋ ๋ค์๊ณผ ๊ฐ์ด ๊ตฌํฉ๋๋ค.
์ด๋ค ๊ณผํ์๊ฐ ๋ฐํํ ๋ ผ๋ฌธ nํธ ์ค, h๋ฒ ์ด์ ์ธ์ฉ๋ ๋ ผ๋ฌธ์ด hํธ ์ด์์ด๊ณ ๋๋จธ์ง ๋ ผ๋ฌธ์ด h๋ฒ ์ดํ ์ธ์ฉ๋์๋ค๋ฉด h์ ์ต๋๊ฐ์ด ์ด ๊ณผํ์์ H-Index์ ๋๋ค.
์ด๋ค ๊ณผํ์๊ฐ ๋ฐํํ ๋ ผ๋ฌธ์ ์ธ์ฉ ํ์๋ฅผ ๋ด์ ๋ฐฐ์ด citations๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, ์ด ๊ณผํ์์ H-Index๋ฅผ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.
์ ํ์ฌํญ
- ๊ณผํ์๊ฐ ๋ฐํํ ๋ ผ๋ฌธ์ ์๋ 1ํธ ์ด์ 1,000ํธ ์ดํ์ ๋๋ค.
- ๋ ผ๋ฌธ๋ณ ์ธ์ฉ ํ์๋ 0ํ ์ด์ 10,000ํ ์ดํ์ ๋๋ค.
์ ์ถ๋ ฅ ์
citationsreturn
[3, 0, 6, 1, 5] | 3 |
์ ์ถ๋ ฅ ์ ์ค๋ช
์ด ๊ณผํ์๊ฐ ๋ฐํํ ๋ ผ๋ฌธ์ ์๋ 5ํธ์ด๊ณ , ๊ทธ์ค 3ํธ์ ๋ ผ๋ฌธ์ 3ํ ์ด์ ์ธ์ฉ๋์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋๋จธ์ง 2ํธ์ ๋ ผ๋ฌธ์ 3ํ ์ดํ ์ธ์ฉ๋์๊ธฐ ๋๋ฌธ์ ์ด ๊ณผํ์์ H-Index๋ 3์ ๋๋ค.
๋์ ํ์ด
def solution(citations):
totalCount = len(citations)
maxNum = max(citations)
index = []
for i in range(maxNum):
tempUp = []
tempDown = []
print("i+1์ ๊ฐ : {}".format(i+1))
for quote in citations:
print("quote : {}".format(quote))
if quote >= i+1:
tempUp.append(quote)
elif quote <= i+1:
tempDown.append(quote)
print("tempUp : {}".format(tempUp))
print("tempDown : {}".format(tempDown))
if i + 1 == len(tempUp) and (totalCount-i-1) == len(tempDown):
index.append(i+1)
return max(index)
๋๋ ์ธ์ฉํ์ (i)๋ฅผ ๊ธฐ์ค์ผ๋ก i+1์ด์์ธ ๋ ผ๋ฌธ, i+1์ดํ์ธ ๋ ผ๋ฌธ์ ๋ค๋ฅธ ๋ฆฌ์คํธ๋ก ๋ฐ๋ก ๋ด์์ ๋ฌธ์ ์ ์กฐ๊ฑด์ด ๋ง์กฑํ๋ฉด ๊ทธ i๋ฅผ ๋๋ค๋ฅธ ๋ฆฌ์คํธ์ ๋ด์ ๊ทธ ์ค์ ์ ์ผ ํฐ ๊ฐ์ ๋ฆฌํดํ๋ ๋ฐฉ์์ ์๊ฐํ๋ค.
[5,5,5,5] ์๊ฐ์ ํ ์คํธ ์ผ์ด์ค๊ฐ ์์๋๋ ๋ญ ๋ฆฌํดํ๋์ง ๋ชจ๋ฅด๊ฒ ๋ค. ๋ฌธ์ ์๋ ์ค๋ช ์ด ์๋์ด์๋๋ฐ ์ด๋ป๊ฒ ํ๋ผ๋๊ฑฐ์ง ์ฆ๋ง ์ด์ดใฑใ ์๋ค์์์ฅใ ์ด์ด์ด์ด์!!!
๋ค๋ฅธ ์ฌ๋ ํ์ด
def solution(citations):
citations.sort(reverse=True)
print(list(enumerate(citations, start=1)))
print(map(min, enumerate(citations, start=1)))
answer = max(map(min, enumerate(citations, start=1)))
print(answer)
return answer
citations = [3, 0, 6, 1, 5]
solution(citations)
๋ฌด์จ ์๋ฆฌ์ธ๊ฑฐ์ง ๋์ค์ ์ต์๊ฐ์ ์ ๊ตฌํ๋๊ฑฐ์ผ?