Internet interview questions: find one of the three numbers with an odd number in an array

Source: Internet
Author: User

2 , Number of special characters ( 25 Points)
In N Integer Array A Only three numbers appear once. 2 Times. Please writeProgramOutput any number that appears only once. The smaller the program time and space complexity, the better.
For example: A = {, 7} , Output 4 Or 5 Or 6

 

// Ing Number Problem # include <iostream> using namespace STD; int lowbit (int x) {return X &~ (X-1);} void find (int A [], int N) {int I, xors; xors = 0; for (I = 0; I <n; ++ I) {xors ^ = A [I];} // two different or lower lowbits of the three numbers are the same. One difference can be divided into two groups: int FIPS = 0; for (I = 0; I <n; ++ I) {FIPS ^ = lowbit (xors ^ A [I]);} // indicates: flips = lowbit (a ^ B) ^ lowbit (a ^ c) ^ lowbit (B ^ c) int B; // assume that one of the three values only appears once is B = 0; for (I = 0; I <n; ++ I) {If (lowbit (xors ^ A [I]) = FIPs) {B ^ = A [I] ;}} // a number of cout <B <Endl;} void main () {int A [] = {, 6} is successfully found }; find (A, sizeof (a)/sizeof (A [0]);}

 

Related Article

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.