Posts Single Number I
Post
Cancel

Single Number I

Problem Description

Given an array of integers A, every element appears twice except for one. Find that integer that occurs once.

Solution

1
2
3
4
5
public int singleNumber(final List<Integer> A) {
    int ans = 0;
    for(int i=0; i<A.size(); i++) ans^= A.get(i);
    return ans;
}
This post is licensed under CC BY 4.0 by the author.