Publish:

ํƒœ๊ทธ: , , , , ,

์นดํ…Œ๊ณ ๋ฆฌ:

img_3.png

๋ฌธ์ œ

๋ฌธ์ œ ๋งํฌ

img_3.png

๋ฐœํ‘œํ•œ ๋…ผ๋ฌธ ์ค‘ h ๋ฒˆ ์ด์ƒ ์ธ์šฉ๋œ ๋…ผ๋ฌธ์˜ ๊ฐฏ์ˆ˜๊ฐ€ ๋ฐฐ์—ด์— ๋ช‡ ๊ฐœ ์žˆ๋Š”์ง€ ํ™•์ธ ํ›„ ์ตœ๋Œ€ ๊ฐ’์„ ๋ฆฌํ„ดํ•ด์•ผ ํ•œ๋‹ค.

์ •๋ ฌํ•˜์ง€ ์•Š๊ณ  ํ‘ธ๋Š” ๋ฐฉ๋ฒ•

๋…ผ๋ฌธ์˜ ์ธ์šฉ ํšŸ์ˆ˜๊ฐ€ ํ˜„์žฌ ๋ฐฐ์—ด์—์„œ ๋ช‡๋ฒˆ ๋‚˜์™”๋Š”์ง€ ๊ธฐ๋กํ•  count ๋ฐฐ์—ด์„ ๋งŒ๋“ ๋‹ค. ์ด ๋ฐฐ์—ด์˜ ์ธ๋ฑ์Šค๊ฐ€ ์ธ์šฉ ํšŸ์ˆ˜(h)์ด๋ฉฐ, ๊ฐ’์€ ํ•ด๋‹น ์ธ์šฉ ํšŸ์ˆ˜์— ํ•ด๋‹นํ•˜๋Š” ๋…ผ๋ฌธ์˜ ์ˆ˜๊ฐ€ ๋œ๋‹ค.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution {
  public int solution(int[] citations) {
    int n = citations.length;
    int[] count = new int[n + 1];

    // ์ธ์šฉ ํšŸ์ˆ˜ ์นด์šดํŠธ
    for (int c : citations) {
      if (c >= n) {
        count[n]++;
      } else {
        count[c]++;
      } 
    }
    
    // H-index ๊ณ„์‚ฐ
    int total = 0;
    for (int i = n; i >= 0; i--) {
      total += count[i];
      if (total >= i) {
        return i;
      }
    }
    
    return 0;
  }
}

count ๋ฐฐ์—ด์€ ๊ฐ ๋…ผ๋ฌธ์˜ ์ธ์šฉํšŸ์ˆ˜์— ๋Œ€ํ•œ ์นด์šดํŠธ๋ฅผ ์ €์žฅํ•˜๋Š” ์—ญํ• ์ด๊ธฐ ๋•Œ๋ฌธ์— ํฌ๊ธฐ๋Š” n + 1 ๋กœ ํ•œ๋‹ค. ๋…ผ๋ฌธ์˜ ์ธ์šฉํšŸ์ˆ˜๊ฐ€ ๋…ผ๋ฌธ ์ˆ˜๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ๊ฒฝ์šฐ์—” count[n] ์— ์ €์žฅ๋œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, [3, 0, 6, 1, 5] ๊ฐ€ ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์กŒ์„๋•Œ count ๋ฐฐ์—ด์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ˆœ์„œ๋กœ ์ฑ„์›Œ์ง„๋‹ค.

1
2
// 3 ์œ„์น˜ count+1 => 0 ์œ„์น˜ count+1 => 6 ์œ„์น˜ count+1 (5์œ„์น˜) => 1 ์œ„์น˜ count+1 => 5 ์œ„์น˜ count+1 
[0, 0, 0, 1, 0, 0] => [1, 0, 0, 1, 0, 0] => [1, 0, 0, 1, 0, 1] => [1, 1, 0, 1, 0, 1] => [1, 1, 0, 1, 0, 2]
  • 0๋ฒˆ ์ธ์šฉ๋œ ๋…ผ๋ฌธ ๊ฐฏ์ˆ˜ : 1
  • 1๋ฒˆ ์ธ์šฉ๋œ ๋…ผ๋ฌธ ๊ฐฏ์ˆ˜ : 1
  • 3๋ฒˆ ์ธ์šฉ๋œ ๋…ผ๋ฌธ ๊ฐฏ์ˆ˜ : 1
  • 5๋ฒˆ ์ด์ƒ ์ธ์šฉ๋œ ๋…ผ๋ฌธ ๊ฐฏ์ˆ˜ : 2

์นด์šดํŠธ ๊ฐ’์„ ๋’ค์—์„œ ๋ถ€ํ„ฐ ๋”ํ•˜๋ฉด 3๋ฒˆ ์ด์ƒ ์ธ์šฉ๋œ ๋…ผ๋ฌธ ๊ฐฏ์ˆ˜๊ฐ€ 3์ผ๋•Œ ์ด ๊ฐ’์ด h-index ๊ฐ€ ๋œ๋‹ค.

์ •๋ ฌ ํ›„ ํ’€์ด

ํฐ ์ธ์šฉ ํšŸ์ˆ˜๊ฐ€ ์ž‘์€ ์ธ์šฉํšŸ์ˆ˜๋ฅผ ํฌํ•จํ•˜๋ฏ€๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

h n
6 1
5 2
3 3
1 4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
  public int solution(int[] citations) {
    int answer = 0;
    Integer[] array = Arrays.stream(citations).boxed().toArray(Integer[]::new);
    Arrays.sort(array, Collections.reverseOrder());

    for (int i = 0; i < array.length; i++) {
      if (array[i] >= i + 1) {
        answer = i + 1;
      } else {
        break;
      }
    }
    return answer;
  }
}
๋ฐฉ๋ฌธํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๋Œ“๊ธ€,์ง€์ ,ํ”ผ๋“œ๋ฐฑ ์–ธ์ œ๋‚˜ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค๐Ÿ˜Š

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ