simple java solution


  • 0
    Q

    public class Solution {
    public int majorityElement(int[] nums) {
    Arrays.sort(nums);
    if(nums.length % 2 == 0) return nums[nums.length/2];
    else return nums[(nums.length - 1) / 2];
    }
    }


Log in to reply
 

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