Home > Back-end >  As soon as possible find out N appears only once in the array number and several other random number
As soon as possible find out N appears only once in the array number and several other random number

Time:09-17

It into a final exam to find two appears only once in the array number,
I'll expand this problem, is there any way to find out as soon as possible find out N appears only once in the array number, I check to baidu baidu's day an interview, just like I didn't want to,
I want to own a two methods all have no success,
Seek solutions,

CodePudding user response:

I don't know the stupid way, as soon as possible,

CodePudding user response:

What's the idea

CodePudding user response:

N array string into a new array, quick sort, scanning array by adjacent element (an element and elements are different before and after) you can judge only once,

CodePudding user response:

This is a problem of elementary school students ~

CodePudding user response:

reference 4 floor zdhsoft response:
this is primary problem ~

,,, I am the elementary student's level, predecessors have what idea, in addition to N arrays into one,

CodePudding user response:

memcpy

CodePudding user response:

reference 5 floor junloin reply:
Quote: refer to 4th floor zdhsoft response:

This is a question of primary school students ~

,,, I am the elementary student's level, predecessors have what idea, in addition to N a string into an array,

Han! You can use the Map & lt; Int, int> The first is that you, the second is the count, after all the data again, then find the count of 1

CodePudding user response:

If you know the number range, to use barrels, traverse all arrays, to the value of a number of corresponding position plus 1, finally through the barrel, if the value of 1 means that the only one

CodePudding user response:

reference u010165006 reply: 3/f
string N array into a new array, quick sort, scanning array by adjacent element (an element and elements are different before and after) you can judge only once,

In this way, he would run into an extreme case, is the same number, a number of consecutive appeared, such as:
1,1,1,1,1,1,1,2,1,1,1,1,1,1,1
This kind of words, check the number of adjacent is meaningless,,

CodePudding user response:

Now think of is two layers of circulation to resolve the problem, also did not think faster than this,,,

CodePudding user response:

Array is very big, you can use bitmap method, need 512 MB of additional space

CodePudding user response:

refer to 7th floor zdhsoft response:
Quote: refer to fifth floor junloin response:

Quote: refer to 4th floor zdhsoft response:

This is a question of primary school students ~

,,, I am the elementary student's level, predecessors have what idea, in addition to N a string into an array,

Han! You can use the Map & lt; Int, int> The first is that you, the second is the count, after all the data again, then find the count of 1 ok


This is good
  • Related