Skip to content

Commit 6b53bf1

Browse files
authored
Create element-appearing-more-than-25-in-sorted-array.py
1 parent de6192f commit 6b53bf1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(logn)
2+
# Space: O(1)
3+
4+
import bisect
5+
6+
7+
class Solution(object):
8+
def findSpecialInteger(self, arr):
9+
"""
10+
:type arr: List[int]
11+
:rtype: int
12+
"""
13+
for x in [arr[len(arr)//4], arr[len(arr)//2], arr[len(arr)*3//4]]:
14+
if (bisect.bisect_right(arr, x) - bisect.bisect_left(arr, x)) * 4 > len(arr):
15+
return x
16+
return -1

0 commit comments

Comments
 (0)