From a8bd54d0d28e6e7e7556cef364cfa3e9c86bb50c Mon Sep 17 00:00:00 2001 From: Lam Haoyin Date: Tue, 22 Feb 2022 00:39:55 +0800 Subject: [PATCH] add: 220221 [csharp] --- csharp/Feb22/Feb22.sln | 6 ++++++ csharp/Feb22/int-0221/Program.cs | 24 ++++++++++++++++++++++++ csharp/Feb22/int-0221/int-0221.csproj | 11 +++++++++++ 3 files changed, 41 insertions(+) create mode 100644 csharp/Feb22/int-0221/Program.cs create mode 100644 csharp/Feb22/int-0221/int-0221.csproj diff --git a/csharp/Feb22/Feb22.sln b/csharp/Feb22/Feb22.sln index d49791e..2aded55 100644 --- a/csharp/Feb22/Feb22.sln +++ b/csharp/Feb22/Feb22.sln @@ -2,6 +2,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cn-0221", "cn-0221\cn-0221.csproj", "{80105805-C505-4A25-BAE2-1F8AC43D53E7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "int-0221", "int-0221\int-0221.csproj", "{9CCC88EF-7FA3-4406-B41B-EAC86AEF8760}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -12,5 +14,9 @@ Global {80105805-C505-4A25-BAE2-1F8AC43D53E7}.Debug|Any CPU.Build.0 = Debug|Any CPU {80105805-C505-4A25-BAE2-1F8AC43D53E7}.Release|Any CPU.ActiveCfg = Release|Any CPU {80105805-C505-4A25-BAE2-1F8AC43D53E7}.Release|Any CPU.Build.0 = Release|Any CPU + {9CCC88EF-7FA3-4406-B41B-EAC86AEF8760}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9CCC88EF-7FA3-4406-B41B-EAC86AEF8760}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9CCC88EF-7FA3-4406-B41B-EAC86AEF8760}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9CCC88EF-7FA3-4406-B41B-EAC86AEF8760}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/csharp/Feb22/int-0221/Program.cs b/csharp/Feb22/int-0221/Program.cs new file mode 100644 index 0000000..c793307 --- /dev/null +++ b/csharp/Feb22/int-0221/Program.cs @@ -0,0 +1,24 @@ +namespace int_0221; + +public class Solution { + public int MajorityElement(int[] nums) { + var m = new Dictionary(); + var n = nums.Length >> 1; + foreach (var i in nums) { + if (m.ContainsKey(i)) + ++m[i]; + else + m[i] = 1; + if (m[i] > n) + return i; + } + // Never reaches + return 0; + } +} + +public class Runner { + private static void Main() { + // Tested in C++ + } +} diff --git a/csharp/Feb22/int-0221/int-0221.csproj b/csharp/Feb22/int-0221/int-0221.csproj new file mode 100644 index 0000000..b71b083 --- /dev/null +++ b/csharp/Feb22/int-0221/int-0221.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + int_0221 + enable + enable + + +