I just saw Wang Xiaohua. In the preface to the "Fun of Algorithms" book, an interview question was mentioned:
There is a sequence of several positive integers, each number in the sequence does not exceed 32, and there are duplicate numbers in the known sequence, please give an algorithm to find out all the repeated numbers in this series.
I implemented a method in Java:
Package Com.wr.findsamenum;public class Findsamenum {public static void main (string[] args) {int[] myinput = {1,2,3,4,5,32 , 5,15,14,2}; Count (myinput);} public static void Count (int[] input) {int[] MySet = new Int[33];for (int i = 0; i < input.length; i++) {for (int j = 0; j <= 32; J + +) {if (input[i] = = j) {myset[j]++;}}} for (int i = 0; I <=, i + +) {if (Myset[i] >= 2) {System.out.println (i);}}}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Fun in Algorithms" preface to the Interview algorithm.