Learn the beauty of programming quickly find faulty machines

Source: Internet
Author: User

Such problems and methods are common. The main idea is to open up, to tell the known problems to abstract into a mathematical model or function expression, which is the true meaning of mathematical modeling, problem solving (the ability to solve practical problems).

Method One: Use the count sort, use an array to write down the number of occurrences of each ID, and then find the ID that appears once, the space-time complexity is O (N). Now if the amount of data is large, then the complexity of this space is not tolerated

Method Two: The use of two the same number of different or the result is 0, all the IDs are different or again, obviously the last remaining value, that is, the number of occurrences 1 times.

Law three: If there are two data once the case, or the use of XOR, but only two occurrences of the data is divided into two piles, and then use the method two.

Just how to divide this is the key, actually can also use XOR, after all, all XOR is equivalent to the two data xor, then there must be a bit of 1, the use of this bit is 1, all the data into two piles.
This is similar to the idea of classifying discussions in mathematics.

Learn the beauty of programming quickly find faulty machines

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.