C# solution


  • 0
    public class Solution {
        public int SingleNumber(int[] nums) 
        {
            if(nums.Length ==1)
            {
                return nums[0];
            }
            Dictionary<int,int> result = new Dictionary<int, int>();
            
            for(int i = 0;i<nums.Length;i++)
            {
                int outInt;
                if(!result.TryGetValue(nums[i], out outInt))
                {
                    result.Add(nums[i], nums[i]);
                }
                else
                {
                    result.Remove(nums[i]);
                }
                
            }
            int returnVal = -1;
            foreach(KeyValuePair<int, int> kvp in result)
            {
                returnVal = kvp.Value;
            }
            return returnVal;
        }
    }
    

Log in to reply
 

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