Single Number


Given an array of integers, every element appears twice except for one. Find that single one.

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?


class Solution {
    int singleNumber(int A[], int n) {
        int r = 0;
        for (int i = 0; i < n; i++) {
            r ^= A[i];
        return r;

One thought on “Single Number

  1. Pingback: Single Number II | ZRJ

Leave a Reply

Your email address will not be published. Required fields are marked *