Sign in to follow this  

Binary search.. or something

This topic is 4399 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an array of numbers, say: 1,2,3,7,7,7,8,9,9. From this array I want to make another array containing only the unique numbers (no duplicates), like so: 1,2,3,7,8,9. Simple, do something like this: for each number in array1 if not number exists in array2 then add number to array2 The problem is that I want it to be fairly fast and because of the array is huge looping through array2 to check if a number already exists gets slow. So I was thinking of sorting the arrays and do a binary search. Or is there some other clever way?

Share this post


Link to post
Share on other sites

This topic is 4399 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this