C++ O(nlogn) solution

  • 0

    As the array is already sorted,we could choose the number which its indice is n/2 as the result.

        int majorityElement(vector<int>& nums)
            int len=nums.size();
            return nums[len/2];

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.