public class Solution {
public int singleNumber(int[] nums) {
//************ Better solution using XOR
// 0 ^ N = N
// N ^ N = 0
int ans = 0;
for(int n : nums){
ans = ans ^ n;
}
return ans;
}
}
public class Solution {
public int singleNumber(int[] nums) {
Arrays.sort(nums); //***
int i =0;
int j = 0;
while (i< nums.length){
if ( i < nums.length -1){
j = i+1;
}
if (nums[i] != nums[j]){
return nums[i];
}else{
i = i+2;
}
}
return nums[0];
}
}