首页 > 代码库 > Problem Single Number

Problem Single Number

Problem Description:

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

Solution:

 1 public int singleNumber(int[] A) { 2         Arrays.sort(A); 3         for (int i = 1; i < A.length; i += 2) { 4             if (A[i-1] != A[i]) { 5                 return A[i-1]; 6             } 7         } 8  9         return A[A.length - 1];10     }