"Fun in Algorithms" preface to the Interview algorithm.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.