137. Single Number II

Source: Internet
Author: User

    /** 137. Single number II * 2016-5-22 by Mingyang * This topic is my idea, you think Ah, each of the numbers are used in binary to indicate, each bit above the sum of 1 of the number should be 3 integer times * If not, then that bit is more 1, so we can use a & to know all the first position on the situation, and then 1 to move to 10, you can also move the * to check the number to the right to move a bit, so that the second bit is moved to the first, and the corresponding array is also counted * so we get an array in the back contains a lot of 1 The number is above, and finally we will restore each of the modules after 3, add to Res*/      Public intSingleNumber1 (int[] A) {if(a.length = = 0| | a==NULL)              return0; int[] cnt =New int[32];  for(inti = 0; i < a.length; i++){               for(intj = 0; J < 32; J + +){                  if((A[i]>>j & 1) ==1) {Cnt[j]++; }              }          }          intres = 0;  for(inti = 0; I < 32; i++) {res+ = (cnt[i]%3 <<i); //Res |= (cnt[i]%3 << i);} CNT=NULL; returnRes; }

137. Single Number II

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.