[Programmers] H 인덱스

Time Lapse :10min 0sec

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <string>
#include <vector>
#include <iostream>
using namespace std;

int solution(vector<int> citations) {
vector<int> inyoung(10001,0);
int max_inyoung = 0;
int total_inyoung = 0;
for(int i=0;i<citations.size();i++){
inyoung[citations[i]]+=1;
max_inyoung = max_inyoung < citations[i] ? citations[i]:max_inyoung;
total_inyoung += 1;
}
int answer = 0;
int cur_inyoung = total_inyoung;
for(int i=0;i<=max_inyoung;i++){
if(cur_inyoung>=i&&total_inyoung-cur_inyoung<=i)
answer = i;
cur_inyoung -= inyoung[i];
}
return answer;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/Hindex/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.