C# Solution; Beats ~96% submissions


  • 0
    C

    '''
    public class Solution {
    public int[] FindErrorNums(int[] nums)
    {
    var sumOfAll = nums.Sum();
    var set = new HashSet<int>(nums);
    var sumOfSet = set.Sum();
    var duplicatedNumber = sumOfAll - sumOfSet;
    var missingNumber = -1;

            for (var i = 1; i <= nums.Length; ++i)
            {
                if (!set.Contains(i))
                {
                    missingNumber = i;
                    break;
                }
            }
    
            return new[] {duplicatedNumber, missingNumber};
        }
    

    }

    '''


Log in to reply
 

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