Contents

H-Index (with.Java)

   Aug 5, 2024     1 min read

H-Index (with.Java) ๋ฌธ์ œ์— ๋Œ€ํ•˜์—ฌ ์•Œ์•„๋ณธ ๊ธ€์ž…๋‹ˆ๋‹ค.

์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ ๋ฌธ์ œ๋ฅผ ํ’€๋ฉฐ, ํ’€์—ˆ๋˜ ๋ฌธ์ œ์— ๋Œ€ํ•œ ํšŒ๊ณ ๋ฅผ ํ•ด๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

๋ฌธ์ œ์— ๋Œ€ํ•ด ๋จผ์ € ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

๋ฌธ์ œ

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

๋ฌธ์ œ์— ๋Œ€ํ•œ ๋‚˜์˜ ํ’€์ด

import java.util.Arrays;

class Solution {
    public int solution(int[] citations) {
        int answer = 0;
        Arrays.sort(citations);
        for(int i = 0; i < citations.length; i++){
            int temp = Math.min(citations[i], citations.length - i);
            if(temp >= answer){
                answer = temp;
            }else{
                break;
            }
        }
        return answer;
    }
}

ํ’€์ด ์„ค๋ช…

  • solution ๋ฉ”์„œ๋“œ๋Š” ์ •์ˆ˜ ๋ฐฐ์—ด citations๋ฅผ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค.
  • ์šฐ์„  citations ๋ฐฐ์—ด์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” H-Index๋ฅผ ๊ณ„์‚ฐํ•˜๊ธฐ ์œ„ํ•ด ๋ฐฐ์—ด์„ ์ •๋ ฌํ•˜๋Š” ์ผ๋ฐ˜์ ์ธ ์ ‘๊ทผ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.
  • ๊ทธ๋Ÿฐ ๋‹ค์Œ for ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฐ์—ด์„ ์ˆœํšŒํ•ฉ๋‹ˆ๋‹ค.
  • ๊ฐ ์ธ์šฉ ํšŸ์ˆ˜ citations[i]์™€ ๋‚จ์€ ๋…ผ๋ฌธ ์ˆ˜์ธ citations.length - i ์ค‘ ์ž‘์€ ๊ฐ’์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ฐ’์ด ํ˜„์žฌ์˜ H-Index ํ›„๋ณด๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
  • ํ˜„์žฌ H-Index ํ›„๋ณด๊ฐ€ ์ด์ „์˜ H-Index ํ›„๋ณด๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๋‹ค๋ฉด answer๋ฅผ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.
  • ์ดํ›„์˜ ๊ฐ’๋“ค์€ ๋” ์ž‘์•„์ง€๋ฏ€๋กœ, ๋” ์ด์ƒ H-Index๊ฐ€ ์ฆ๊ฐ€ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ break๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ˜๋ณต๋ฌธ์„ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.
  • ์ตœ์ข…์ ์œผ๋กœ answer๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

๊ฒฐ๋ก 

์ด ์ฝ”๋“œ๋Š” ๋…ผ๋ฌธ ์ธ์šฉ ํšŸ์ˆ˜ ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜์—ฌ H-Index๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š”๋ฐ, ๋ฐฐ์—ด์„ ์ •๋ ฌํ•œ ํ›„์— ๋ฐ˜๋ณต๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ H-Index ํ›„๋ณด๋ฅผ ์ฐพ๊ณ  ์ด๋ฅผ ๊ฒ€์ฆํ•˜๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.