We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 64b94e0 commit ad47fb8Copy full SHA for ad47fb8
1 file changed
Python/h-index.py
@@ -1,5 +1,5 @@
1
-# Time: O(nlogn)
2
-# Space: O(1)
+# Time: O(n)
+# Space: O(n)
3
4
# Given an array of citations (each citation is a non-negative integer)
5
# of a researcher, write a function to compute the researcher's h-index.
@@ -19,6 +19,29 @@
19
#
20
21
class Solution(object):
22
+ def hIndex(self, citations):
23
+ """
24
+ :type citations: List[int]
25
+ :rtype: int
26
27
+ n = len(citations);
28
+ count = [0] * (n + 1)
29
+ for x in citations:
30
+ if x >= n:
31
+ count[n] += 1
32
+ else:
33
+ count[x] += 1
34
+
35
+ h = 0
36
+ for i in reversed(xrange(0, n + 1)):
37
+ h += count[i]
38
+ if h >= i:
39
+ return i
40
+ return h
41
42
+# Time: O(nlogn)
43
+# Space: O(1)
44
+class Solution2(object):
45
def hIndex(self, citations):
46
"""
47
:type citations: List[int]
0 commit comments