-
Notifications
You must be signed in to change notification settings - Fork 0
/
275.py
49 lines (35 loc) · 1.06 KB
/
275.py
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
43
44
45
46
47
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = ['"wuyadong" <[email protected]>']
class Solution(object):
def hIndex(self, citations):
"""
:type citations: List[int]
:rtype: int
"""
n = len(citations)
if n == 0:
return 0
start = 0
end = n-1
while start < end:
if start+1 == end:
if n-end >= citations[end]:
h = citations[end]
else:
h = n-end
if n-start >= citations[start]:
if citations[start] > h:
h = citations[start]
else:
if n-start > h:
h = n-start
return h
mid = (start+end)/2
if n-mid >= citations[mid]:
start = mid
else:
end = mid
return citations[start] if n-start >= citations[start] else n-start
if __name__ == '__main__':
print Solution().hIndex([100])