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

代码如下:

 1 public class Solution {
 2     public int singleNumber(int[] nums) {
 3         if(nums.length==1)
 4         return nums[0];
 5         
 6         Arrays.sort(nums);
 7         int s=0;
 8         for(int i=0;i<nums.length-1;)
 9         {
10             if(nums[i]==nums[i+1])
11             i=i+2;
12             else 
13             {return nums[i]; }
14         }
15        
16         return nums[nums.length-1];
17          
18     }
19 }