LeetCode solutions

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

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 16.2MB, accepted 2025-12-27.

cpp
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;
    }
};

Source