My Easy to understand Answer -java


  • -5
    S
    public class Solution {
    public int singleNumber(int[] nums) {
        int n = nums.length, i;
        if(n == 1)
            return nums[0];
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    	for (i = 0; i < n; i++) {
    		if (map.containsKey(nums[i]) == true)
    			map.remove(nums[i]);
    		else
    			map.put(nums[i], 2);
    	}
    	String a = map.toString();
    	String b = "";
    	for(i = 1; i < a.length(); i ++) {
    	    if(a.charAt(i) == '=')
    	        b = b.concat(a.substring(1,i));
    	}
    	return Integer.parseInt(b);
    }
    

    }


Log in to reply
 

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