Only 2 lines C++ code

  • -11

    This question is not so hard. We know that only the majority no. has n/2 times. So after sorting the middle value in this vector is the result.

    class Solution {

    int majorityElement(vector<int> &num) {
    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.