Laziest java solution with only two lines

  • 0

    After sorting the array, the majority element will definitely show up in the middle point. This works for both odd and even lengths' arrays.

    class Solution {
        public int majorityElement(int[] nums) {
            return nums[nums.length / 2];

Log in to reply

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