O(1) space, no bit manipulation, easy C# solution


  • -5
    E
     public int SingleNumber(int[] nums) 
        {
            Array.Sort(nums);
            
            for(int i= 0; i< nums.Length; i++)
            {
                if(i+2<nums.Length &&  nums[i] == nums[i+1] && nums[i+1] == nums[i+2])
                {
                     i += 2;
                }
                else
                {
                    return nums[i];
                }
            }
            
            return 0;
        }

  • 0
    L

    Dude, you got to do it in linear runtime complexity.


Log in to reply
 

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