1221. Element Appearing More Than 25% In Sorted Array
My accepted C++ solution to LeetCode problem 1221, Element Appearing More Than 25% In Sorted Array, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 16.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 16.2MB, accepted 2025-12-27.
class Solution {
public:
int findSpecialInteger(vector<int>& arr) {
int n = arr.size(), threshold = n / 4;
for (int i = 0; i < n; i++) {
if (arr[i] == arr[i + threshold]) return arr[i];
}
return -1;
}
};