Java solution easy to understand


  • -2
    N
    public static int singleNumber(int[] nums) {
            HashSet<Integer> rs=new HashSet<Integer>();
            for(int i=0;i<nums.length;i++)
            {
            	if(!rs.add(nums[i]))  rs.remove(nums[i]);
            }
            return rs.iterator().next();
     }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.