Created
July 23, 2023 01:13
-
-
Save unilecs/474684d932992f3d4a684811a5d0b938 to your computer and use it in GitHub Desktop.
Задача. Единственный элемент
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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