Skip to content

Commit ea72a8d

Browse files
committed
Element Appearing More Than 25% In Sorted Array
1 parent 515ef64 commit ea72a8d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
""" https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/ """
2+
3+
class Solution:
4+
def findSpecialInteger(self, arr):
5+
nums = []
6+
freqs = []
7+
8+
for num in arr:
9+
if num not in nums:
10+
nums.append(num)
11+
freqs.append(1)
12+
else:
13+
freqs[nums.index(num)] += 1
14+
15+
totalFreqs = sum(freqs)
16+
17+
for freq in freqs:
18+
if (freq / totalFreqs > 0.25):
19+
return nums[freqs.index(freq)]
20+
21+
print(Solution().findSpecialInteger([1,2,2,6,6,6,6,7,10]))

0 commit comments

Comments
 (0)