A java solution


  • 0
    X

    public class Solution {
    public int singleNumber(int[] nums) {
    HashMap<Integer,Integer> map = new HashMap<Integer, Integer>();
    for(int i = 0; i<nums.length; i++){
    if(map.containsKey(nums[i])==false){
    map.put(nums[i],1);
    }
    else{
    map.remove(nums[i]);
    }
    }
    List<Integer> answer = new ArrayList<Integer>(map.keySet());
    return answer.get(0);

    }
    

    }


Log in to reply
 

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