Given an array of integers, every element appears twice except for one. Find that single one.
public class Solution {
public int singleNumber(int[] nums) {
if(nums.length==1){
return nums[0];
}else if(nums.length%2 == 0){
return 0;
}else{
Arrays.sort(nums);
int n = nums.length-1;
for(int i=0;i<n;i+=2){
if(nums[i] != nums[i+1]){
return nums[i];
}
}
return nums[n];
}
}
}