add: 220221 [csharp]

This commit is contained in:
Lam Haoyin 2022-02-22 00:39:55 +08:00
parent 9137b94bf7
commit a8bd54d0d2
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
3 changed files with 41 additions and 0 deletions

View File

@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00 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}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cn-0221", "cn-0221\cn-0221.csproj", "{80105805-C505-4A25-BAE2-1F8AC43D53E7}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "int-0221", "int-0221\int-0221.csproj", "{9CCC88EF-7FA3-4406-B41B-EAC86AEF8760}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{80105805-C505-4A25-BAE2-1F8AC43D53E7}.Release|Any CPU.Build.0 = 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 EndGlobalSection
EndGlobal EndGlobal

View File

@ -0,0 +1,24 @@
namespace int_0221;
public class Solution {
public int MajorityElement(int[] nums) {
var m = new Dictionary<int, int>();
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++
}
}

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>int_0221</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>