C++ sort solution work around [1,1,2,3]


  • 0
    class Solution {
    public:
        int majorityElement(vector<int>& nums) {
            int len = nums.size();
            sort(nums.begin(),nums.end());
            return nums[len/2-(!(len%2))];
        }
    };
    

Log in to reply
 

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