Leetcode 260 Single number III also or

Source: Internet
Author: User

Find two distinct occurrences in an array (the other number appears two times)

Also used or solved (refer to the beauty of programming 1.5)

To take out the total or value first.

Then classify it into ans[0] and ans[1 on the last digit appearing 1 )

a& (-a) calculates this number and can refer to a tree-like array.

The last one is attention . (Nums[i] & a) = = 0 To add (). Note the priority of symbolic operations

1 classSolution {2  Public:3vector<int> Singlenumber (vector<int>&nums) {4         intA =0;5          for(inti =0; I<nums.size (); ++i) {6A ^=Nums[i];7         }8vector<int> Ans (2,0);9A &= (-a);Ten          for(inti =0; I<nums.size (); ++i) { Oneans[(Nums[i] & a) = =0] ^=Nums[i];  A         } -         returnans; -     } the};

Leetcode 260 Single number III also or

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.