-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
๋ฌธ์ ์ค๋ช | H-Index
์ฐ๊ตฌ์์ ๋
ผ๋ฌธ ์ธ์ฉ ์ ๋ฐฐ์ด citations๊ฐ ์ฃผ์ด์ง ๋, H-Index๋ฅผ ๊ตฌํ๋ ๋ฌธ์
H-Index ์ ์:
- ์ฐ๊ตฌ์๊ฐ ๋ฐํํ ๋ ผ๋ฌธ ์ค h ํธ ์ด์์ด hํ ์ด์ ์ธ์ฉ๋์์ ๋, ๊ฐ๋ฅํ h ๊ฐ ์ค ์ต๋๊ฐ์ ๊ตฌํ๋ค.
๐ ์ ์ฝ์กฐ๊ฑด
1 <= citations.length <= 5000(๋ ผ๋ฌธ์ ๊ฐ์)0 <= citations[i] <= 1000(๊ฐ ๋ ผ๋ฌธ์ ์ธ์ฉ ํ์)
๐ก ์์
Example 1
Input:
citations = [3, 0, 6, 1, 5]Output:
3Explanation:
- ๋
ผ๋ฌธ ์ธ์ฉ ํ์:
[3, 0, 6, 1, 5] - ์ ๋ ฌ ํ:
[6, 5, 3, 1, 0] h = 3์ผ ๋, 3ํธ ์ด์์ด 3ํ ์ด์ ์ธ์ฉ๋จ โ ์ต๋ h-index๋3
๐ ๋ฌธ์ ํด๊ฒฐ ๊ณผ์
Step 1: ๋ฌธ์ ์ดํดํ๊ธฐ
์์ ์์๋ก ์ง์ ๊ณ์ฐํด๋ณด๊ธฐ
| ๋ ผ๋ฌธ ๊ฐ์ | ์ธ์ฉ ํ์ ๋ฐฐ์ด | h-index ๊ณ์ฐ |
|---|---|---|
| 1๊ฐ | [5] |
1 |
| 2๊ฐ | [4, 5] |
2 |
| 3๊ฐ | [10, 8, 5] |
3 |
- ๋
ผ๋ฌธ์ ๊ฐ์๊ฐ
hํธ ์ด์์ด๊ณ , ๊ฐ ๋ ผ๋ฌธ์ด h๋ฒ ์ด์ ์ธ์ฉ๋์์ ๋์h์ค ์ต๋๊ฐ์ ์ฐพ์์ผ ํ๋ค.
Step 2: ์ ๊ทผ ๋ฐฉ๋ฒ
๐ก ์ง๊ด์ ์ธ ์ ๊ทผ๋ฒ (์์ ํ์)
- ๋ชจ๋
h์ ๋ํด ๋ ผ๋ฌธ ๊ฐ์๋ฅผ ์ธ๊ณ ์กฐ๊ฑด์ ๋ง์กฑํ๋h์ค ์ต๋๊ฐ ์ฐพ๊ธฐ โ O(nยฒ) (๋นํจ์จ์ )
๐ก ์ ๋ ฌ์ ํ์ฉํ ๋ฐฉ๋ฒ (O(n log n))
- ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ โ ์ธ์ฉ ํ์๊ฐ ํฐ ์์๋๋ก ์ ๋ ฌ
- ์ผ์ชฝ์์๋ถํฐ ํ์ํ๋ฉด์ h-index ์ฐพ๊ธฐ
- ํ์ฌ
i + 1๊ฐ์ ๋ ผ๋ฌธ์ดcitations[i]์ด์ ์ธ์ฉ๋์๋์ง ํ์ธ - ์กฐ๊ฑด์ด ๊นจ์ง๋ ์๊ฐ, ์ต๋
h๋ฅผ ๋ฐํ
- ํ์ฌ
Step 3: ์ฝ๋ ์ค๊ณ
citations๋ฐฐ์ด์ ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌfor๋ฌธ์ ๋๋ฉด์i + 1๋ฒ์งธ ๋ ผ๋ฌธ์ ์ธ์ฉ ํ์์ ๋น๊ต- ์กฐ๊ฑด์ ๋ง์กฑํ๋ ์ต๋
h-index๋ฅผresult์ ์ ์ฅ - ์กฐ๊ฑด์ด ๊นจ์ง๋ ์๊ฐ
result๋ฐํ
Step 4: ์ฝ๋ ๊ตฌํ
/**
* @param {number[]} citations
* @return {number}
*/
var hIndex = function(citations) {
// 1. ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ
citations.sort((a, b) => b - a);
let result = 0;
// 2. ์ ๋ ฌ๋ ์ํ์์ h-index ์ฐพ๊ธฐ
for (let i = 0; i < citations.length; i++) {
if (citations[i] >= i + 1) {
result = i + 1;
} else {
break; // ์กฐ๊ฑด์ด ๊นจ์ง๋ฉด ์ค๋จ
}
}
return result;
};Metadata
Metadata
Assignees
Labels
No labels