Only two lines after sorting


  • -1
    X

    class Solution {
    public:
    int majorityElement(vector<int> &num) {
    sort(num.begin(),num.end());
    return num[num.size()/2];
    }
    };


Log in to reply
 

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