[#3005] feat(leetcode): init project, add C# solution

This commit is contained in:
2025-09-22 13:48:38 +08:00
parent 7c86a4a99a
commit c7453b45e6
8 changed files with 255 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
// LeetCode 3005: Count_elements_with_maximum_frequency
// 難度: Easy
// 日期: 2025-09-22
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public int MaxFrequencyElements(int[] nums)
{
Dictionary<int, int> frequencyMap = new Dictionary<int, int>();
// put nums into dictionary map
foreach (var num in nums)
{
if (!frequencyMap.ContainsKey(num))
{
frequencyMap.Add(num, 0);
}
frequencyMap[num]++;
}
// find most frequency nums
int maxFrequency = 0;
if (frequencyMap.Count != 0)
{
maxFrequency = frequencyMap.Values.Max();
}
// count if have same max frequency nus
int count = 0;
foreach (var dic in frequencyMap)
{
if (dic.Value == maxFrequency)
{
count += maxFrequency;
}
}
return count;
}
}
public class Program {
public static void Main() {
var s = new Solution();
// TODO: 可加入簡單輸入/輸出測試
Console.WriteLine("Hello LeetCode 3005!");
}
}

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>