Interview question: How to find the number of non-repeating numbers from 300 million integers

Source: Internet
Author: User

Recently saw an interview with Baidu: How to find the number of non-repeating numbers from 250 million integers

Write the following implementation, the time is slightly tight, the idea is slightly coarse, there are errors also please point out. Thank you.

int[] isrepeat = new Int[arr.length]; modified to int[] Isrepeat = new int[250000000];

Need to request the JVM 512M of memory


	public static int GetCount (int[] arr) {
		int norepeatcount = 0;//number of distinct digits
//		int repeatcount = 0;//repeats multiple times 
  int[] isrepeat = new Int[arr.length];
		for (int i:isrepeat) {
			isrepeat[i]=0;
		}
		Read in a number to see if the corresponding flag is 0, if 0,flag 1,count plus 1, if 1, do not process for
		(int i = 0; i < arr.length; i++) {
			int count = 1;
  
   if (Isrepeat[arr[i]] = = 0) {
				Isrepeat[arr[i]] + = count;
			} else if (Isrepeat[arr[i] > 0) {
				Isrepeat[arr [i]] + = count;
			}
		}
		for (int i:isrepeat) {
			if (i = = 1) {
				norepeatcount++;//returns the one that appears once
			} 
//			else if (i > 1) {
   
    // repeatcount++;////Returns the number of repeated occurrences // } } return norepeatcount; } public static void Main (string[] args) throws ParseException { int[] arr = {1, 2, 2, 3, 4, 5, 6, 7, 7, 8, 8, 8, 8, 9 , ten, ten}; System.out.println (GetCount (arr)); }
   
  


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.