3ms solution


  • 1
    R

    Sort the array, return the mid element.


  • 0
    B

    you are wrong,such as [1,1,2,3] or[1,2,3,3].


  • 0
    P

    @bupt_qiuq OP is right. Your input isn't valid. The problem statement says majority element is one that is present "more than" floor(n/2) and we can assume such an element is present. In your input, floor(n/2) = floor(4/2) = 2 and there is no element present more than 2 times.


Log in to reply
 

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