class Solution { public int singleNumber(int[] nums) { HashMap map = new HashMap<>(); for(int i = 0 ; i < nums.length ; ++i){ if(map.containsKey(nums[i])){ map.put(nums[i], map.get(nums[i]) +1); } else { map.put(nums[i],1); } } for(Map.Entry map2 : map.entrySet()){ if(map2.getValue() == 1){ return map2.getKey(); } } throw new IllegalArgumentException(); } } class Solution { public int singleNumber(int[] nums) { int x = 0; for(int i: nums){ x ^= i; } return x; } }