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     }

 

posted @ 2014-06-29 14:40  HaruHaru  阅读(124)  评论(0编辑  收藏  举报