Non-bitwise Java solution using set


  • 10
    T
    public int singleNumber(int[] A) {
            
           Set<Integer> s = new HashSet<Integer>();
    	    for (int i: A){
    	    	if(!s.add(i)){
    	    		s.remove(i);
    	    	}
    	    }
    	    return s.iterator().next();
            
        }

Log in to reply
 

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