leetcode 1287 - Element Appearing More Than 25% In Sorted Array

https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/

Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time.

Return that integer.

Example 1:

Input: arr = [1,2,2,6,6,6,6,7,10]
Output: 6

Constraints:

1 <= arr.length <= 10^4
0 <= arr[i] <= 10^5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public:
int findSpecialInteger(vector<int>& arr) {
int size = arr.size();
vector<int> indexs = {size/4, size/2, size*3/4};

for (int i : indexs) {
int num = arr[i];

auto low = lower_bound(arr.begin(), arr.end(), num);
auto high = upper_bound(arr.begin(), arr.end(), num);

if (high - low > size/4)
return num;
}

return -1;
}
};