Very easy C# solution (not XOR)


  • -3
    E
    public int[] SingleNumber(int[] nums) 
        {
            Array.Sort(nums);
            List<int> singles = new List<int>();
            
            for(int i= 0; i< nums.Length; i++)
            {
                if(i+1<nums.Length &&  nums[i] == nums[i+1])
                {
                     i++;
                }
                else
                {
                    singles.Add(nums[i]);
                }
            }
            
            return singles.ToArray();
        }
    

    this solution handles not just 2 but infinite amount of singles.


  • 0
    B
    Array.Sort(nums);
    

    is not linear. It's n * logn


  • 0
    X

    The idea is trivial. Also, it's not constant space. It requires O(N) additional space.


Log in to reply
 

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