Single Number I

Description

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

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

Hide Company Tags: Palantir Airbnb

Hide Tags: Hash Table Bit Manipulation

Hide Similar Problems: (M) Single Number II (M) Single Number III (M) Missing Number (H) Find the Duplicate Number

Java Solution
public class Solution {
    public int singleNumber(int[] nums) {
        int res = 0;

        for(int num : nums){
            res = res ^ num;
        }

        return res;
    }
}

results matching ""

    No results matching ""