Single Number

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

Solution:

public class Solution {
    public int singleNumber(int[] nums) {
        int ans = 0; 
        for(int n: nums)  ans^=n; 
        return ans;
    }
}

results matching ""

    No results matching ""