[leetcode]single number

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?

解题思路:使用异或,数组中相同的数两两异或全部为0,最后剩下的就是那个落单的数。

public class Solution {
    public int singleNumber(int[] A) {
        int n=0;
        for(int i=0;i

你可能感兴趣的:([leetcode]single number)