C# O(N) Solution by using HashSet


  • 0
    K
    public int MissingNumber(int[] nums) {
        
        HashSet<int> set = new HashSet<int>();
        int missing = int.MinValue;
        
        for(int i = 0; i < nums.Length;i++){
            set.Add(nums[i]);    
        }
        
        for(int i = 0; i <= nums.Length;i++){
            if(!set.Contains(i)) missing = i;
        }
        
        return missing;
    }

Log in to reply
 

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