Solution 1 Naive way First, sort the array using Arrays.sort in Java. Than, scan once to find the majority element. Time complexity O(nlog(n)) public class Solution { public int majorityElement(int[] nums) { int length = nums.length; if (length == 1)…