A number appears 2 times, and the rest of the numbers appear 3 times.

Source: Internet
Author: User

a large array full of numbers, except that one of the numbers appears 2 times, and the remaining numbers appear 3 times. How do I find the number that only happened two times?
Among them, ones recorded that all the Bit,twos records that appeared 3 and 1 times were the remaining 2. Not_threes is when a bit appears for the 3rd time, clear it off.

Public classtest3in2 {/** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method Stub intOnes=0; intTwos=0; intNot_threes=0; inta[]={22,33,22,66,66,33,33,66,55,22,55,55,121,121}; for(inti=0;i<a.length;i++) {twos|=ones&A[i]; Ones^=A[i]; Not_threes=~ (ones&twos); Ones&=not_threes; Twos&=not_threes; } System.out.println ("222====" +twos); System.out.println ("111====" +ones); }}

A number appears 2 times, and the rest of the numbers appear 3 times.

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.