Only one number appears once in a set of data, and the other numbers appear in pairs to find out the number

Source: Internet
Author: User

There is only one number in a set of data that appears once, and all the other numbers are paired, please find this number.

(using bit operations)

Use the XOR operation directly.

The code is as follows:

#include <stdio.h> #include <stdlib.h>int main () {int arr[]={3,5,9,2,5,3,2}; int size=sizeof (arr)/sizeof ( ARR[0]); int i=0,find=0;for (; i<size;i++) {find^=arr[i];//loop for XOR Operation}printf ("%d\n", find); System ("pause"); return 0;}

This article is from the "Materfer" blog, make sure to keep this source http://10741357.blog.51cto.com/10731357/1708445

Only one number appears once in a set of data, and the other numbers appear in pairs to find out the number

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.