-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
42 lines (38 loc) · 862 Bytes
/
Solution.cs
File metadata and controls
42 lines (38 loc) · 862 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public class Solution
{
public int HIndex(int[] citations)
{
Array.Sort(citations, (a, b) => b - a);
int ans = 0;
while (ans < citations.Length && citations[ans] >= (ans + 1))
{
ans++;
}
return ans;
}
private int HIndex_Enhance(int[] citations)
{
var counts = new int[citations.Length + 1];
foreach (var c in citations)
{
if (c >= citations.Length)
{
++counts[citations.Length];
}
else
{
++counts[c];
}
}
int cumCit = 0;
for (int i = citations.Length; i >= 0; --i)
{
cumCit += counts[i];
if (cumCit >= i)
{
return i;
}
}
return 0;
}
}