My two-line JAVA solution


  • 5
    A

    public class Solution {

    public int majorityElement(int[] nums) {
        Arrays.sort(nums);
        return nums[nums.length/2];
    }
    

    }

    • The number we need is the very middle number in the sorted array.

Log in to reply
 

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