I. Design ideas
1. Remove two different IDs from the list each time by looking for them (regardless of whether they contain "water king" id)
2. It was concluded that the number of occurrences was still more than half ID
Two. Code implementation
public class Shuiwang {public static void main (string[] args) {//TODO auto-generated method stubint[] array={5,1,2,3,8,5, 5,5,5,4,5}; System.out.println (Find (array));} public static int Find (int[] array) {int m=array.length;int n=0;int a=0;for (int i=0;i<m;i++) {if (a==0) {n=array[i];a=1 ;} Else{if (N==array[i]) {++a;} else{--a;}}} return n;}}
Three. Implement
Four. Personal summary
I use this algorithm has a disadvantage, do not know exactly How many times this ID appears, can only know that the number of occurrences of the ID more than half , If you want to know, and finally to traverse several times.
Through this class test, I know it is not difficult to make, but to use the best way is that we should consider learning.
Software Engineering Personal Assignment 07