H - index

https://programmers.co.kr/learn/courses/30/lessons/42747

  • h ๋ฅผ 0๋ถ€ํ„ฐ ๋Š˜๋ ค๊ฐ€๋ฉด์„œ ๊ฐ€๋Šฅํ•œ์ง€ ํŒ๋‹จ

  • ์ตœ๋Œ“๊ฐ’์„ ์ถœ๋ ฅํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์—, ์ญ‰์ญ‰ ๊ฐ€๋‹ค๊ฐ€ ์•ˆ ๋˜๋Š” ์‹œ์ ์— ๋„๋‹ฌํ•˜๋ฉด (์‹œ์  - 1) ์„ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋จ

def check(h, c):
    up = 0
    down = 0

    for n in c:
          # ์ด์ƒ์ธ ๊ฒƒ๋งŒ ์„ธ์ž
        if n >= h:
            up += 1
        # ๊ทธ ๋‚˜๋จธ์ง€๋Š” ์–ด์ฐจํ”ผ ๊ทธ ์™ธ์˜ ๋‚˜๋จธ์ง€ ๋…ผ๋ฌธ์ด๋ผ ์ƒ๊ด€์—†์Œ

    if up >= h:
        return True
    else:
        return False


def solution(citations):
    c = citations

    # return h - 1 ์ด๊ธฐ ๋•Œ๋ฌธ์— for ๋ฌธ์—์„œ len(c) + 1 ๊นŒ์ง€ ํ•ด์„œ False ํ•ด์•ผ return len(c) ๊ฐ€ ๋จ
    for h in range(len(c) + 2):
        if check(h, c):
            continue

        else:
            if h == 0:
                return 0
            return h - 1

Last updated