Easy C# Solution using HashSet


  • 1
    A
     public IList<int> FindDisappearedNumbers(int[] nums) {
            HashSet<int> NumbersList = new HashSet<int>();
            List<int> DisappearedNumbers = new List<int>();
            for(int i = 0; i<nums.Length; i++)
            {
                NumbersList.Add(nums[i]);
            }
            for(int i = 1; i<=nums.Length; i++)
            {
                if(!NumbersList.Contains(i))
                {
                    DisappearedNumbers.Add(i);
                }
            }
            return DisappearedNumbers;
        }
    

    Note: HashSet Only accepts unique values.


  • 0
    V

    Is HashSet not an additional space? Just curious


Log in to reply
 

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