An array, some numbers appear 2 times, only two numbers appear once, find out the two numbers

Source: Internet
Author: User

https://leetcode.com/problems/single-number-iii/

The first time you see this problem, you think of the different or, but only to find out the results of the two-digit or, can not find out the two numbers. In the end I used the quick row, and then went to see people's thinking. It seems that we have to carefully analyze the hidden information. For example: from the two number of different or after the result can be seen from the low start to a person is not 0 o'clock, it must be the two number of bits at this time is different (from the low start must be able to find a not 0, because these two numbers are different). This bit can use the Lowbit method of the tree array to vary the XOR value from the negative number of this value. It then divides each number in this array with the number that is only 1 on this bit, thus dividing the array into two groups, and then each of the two sets of numbers is different or the two numbers can be obtained.

An array, some numbers appear 2 times, only two numbers appear once, find out the two numbers

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.