Magic of numbers-2.1

Source: Internet
Author: User
The beauty of programming-Chapter 2-the charm of numbers-2.1-calculate the number of 1 in the binary number-answers to after-school extension questions
1> if it becomes a 32-bit DWORD, it is obvious that solution 4 and solution 5 cannot meet the requirements, because such a large array space cannot be opened and so many numbers cannot be listed manually, let's look at solution 1 and solution 2. the time complexity of the algorithm has not changed. It can also be solved perfectly. In solution 3, the time complexity is still only related to the number of 1, is the optimal solution 2> how many digits are different in the binary representation of integers A and B? Here, we first think that if they are different, we can use an exclusive or operation, and then the problem is converted to finding the number of 1 in a binary number. solution 3 can be used to quickly calculate the number.

Magic of numbers-2.1

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.