Sword refers to offer question 40 (c#)

Sword refers to offer question 40 (c#)

In an integer array, except for two numbers that only appear once, all other numbers appear twice. Please write a program to find these two numbers that appear only once.

At the beginning, I planned to use the hash table to solve the problem, but later I found that some methods of the hash table were not very familiar, so I read other students' solutions. ; So I went back to study the solution of the hash table; first,
insert image description here
create a hash table ( used to record the number of times of each number because the topic is special, so the content in the hash table is directly assigned ) and a list (used to output two singletons)

Then traverse the input list once to record the data that appears once, and delete the data that appears multiple times

Finally, traverse the hash table once and put the saved data into the output list ( since the data in this way is in reverse order from large to small and does not meet the output requirements of the title, Sort it again ) and finally output.

Guess you like

Origin blog.csdn.net/weixin_50746193/article/details/116608907