An integer whose frequency exceeds half is displayed in an array, for example, {3, 2, 3, 3, 0, 2, 3, 4, 3 }, among them, 3 appears 5 times, 5 divided by 9 is greater than 0.5, SO 3 is the supporter. Write a function to find out the number of backend workers in the given integer array. If no backend operator exists in an array, 1 is returned.
Package CN. usst. datatest5; import Java. util. arrays; public class datatest5 {/*** "dominated" is an integer that appears more than half of the frequency in the array * @ Param ARGs */public static void main (string [] ARGs) {int [] ints = {3, 2, 3, 3, 0, 2, 3, 4, 3}; Int J = judge (ints ); if (j =-1) {system. out. println ("No dominator");} else {system. out. println ("the Dominator is:" + ints [J]) ;}} Private Static int judge (INT [] ints) {arrays. sort (ints); int counter = 1; for (INT I = 0; I <(ints. length-1); I ++) {If (ints [I] = ints [I + 1]) {counter ++; If (double) Counter) /ints. length)> 0.5) {return I ;}} else {counter = 1 ;}} return-1 ;}}
"Dominant" is an integer that appears more than half of the frequency in the array.