Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created July 23, 2023 01:13
Show Gist options
  • Save unilecs/474684d932992f3d4a684811a5d0b938 to your computer and use it in GitHub Desktop.
Save unilecs/474684d932992f3d4a684811a5d0b938 to your computer and use it in GitHub Desktop.
Задача. Единственный элемент
using System;
public class Program
{
public static int GetSingleNumber(int[] nums) {
int single = 0;
int twice = 0;
foreach (int num in nums)
{
single = (single ^ num) & ~twice;
twice = (twice ^ num) & ~single;
}
return single;
}
public static void Main()
{
Console.WriteLine("UniLecs");
// tests
Console.WriteLine(GetSingleNumber(new int[] { 2, 2, 3, 2 })); // 3
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment