diff --git a/problems/3005-count_elements_with_maximum_frequency/3005-count_elements_with_maximum_frequency.sln b/problems/3005-count_elements_with_maximum_frequency/3005-count_elements_with_maximum_frequency.sln new file mode 100644 index 0000000..be6df9d --- /dev/null +++ b/problems/3005-count_elements_with_maximum_frequency/3005-count_elements_with_maximum_frequency.sln @@ -0,0 +1,30 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.2.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp", "csharp\csharp.csproj", "{CF022C7B-CAF3-706D-67E1-FB93518229B7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "test\TestProject.csproj", "{C670389A-9CE7-B456-51E5-A79D56E199CF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CF022C7B-CAF3-706D-67E1-FB93518229B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF022C7B-CAF3-706D-67E1-FB93518229B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF022C7B-CAF3-706D-67E1-FB93518229B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF022C7B-CAF3-706D-67E1-FB93518229B7}.Release|Any CPU.Build.0 = Release|Any CPU + {C670389A-9CE7-B456-51E5-A79D56E199CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C670389A-9CE7-B456-51E5-A79D56E199CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C670389A-9CE7-B456-51E5-A79D56E199CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C670389A-9CE7-B456-51E5-A79D56E199CF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {50409315-93FE-4BEF-BAEC-4B70A05B634A} + EndGlobalSection +EndGlobal diff --git a/problems/3005-count_elements_with_maximum_frequency/README.md b/problems/3005-count_elements_with_maximum_frequency/README.md new file mode 100644 index 0000000..d025753 --- /dev/null +++ b/problems/3005-count_elements_with_maximum_frequency/README.md @@ -0,0 +1,91 @@ +# [3005] Count_elements_with_maximum_frequency + +## 題目資訊 +- **難度**: Easy +- **標籤**: +- **題目連結**: https://leetcode.com/problems/count_elements_with_maximum_frequency/ +- **練習日期**: 2025-09-22 +- **目標複雜度**: 時間 O(?)、空間 O(?) + +## 題目描述 +> 在這裡貼上題目的完整描述(或重點) + +## 先備條件與限制 +- 輸入限制:n ∈ [?, ?]、值域 ∈ [?, ?] +- 回傳/輸出格式:... +- 其他:是否允許排序/就地修改 + +## 解題思路 + +### 初步分析 +- 類型:雙指針 / 滑動視窗 / 排序 / DP / 貪心 / 圖論 ... +- 關鍵觀察: +- 複雜度目標理由: + +### 解法比較 +1. 解法A(基準/暴力): + - 思路: + - 正確性: + - 複雜度:O(?) / O(?) +2. 解法B(優化): + - 思路: + - 正確性: + - 複雜度:O(?) / O(?) + +### 乾跑(Dry Run) +- 範例:... + +## 實作細節與 API 設計 + +### C# 方法簽名(示意) +```csharp +public class Solution { + // TODO: 根據題意調整簽名 + public int Solve(int[] nums) { + return 0; + } +} +``` + +### Go 方法簽名(示意) +```go +func solve(nums []int) int { + return 0 +} +``` + +### 常見陷阱 +- 邊界:空/單一/極值/全相等 +- 去重:排序後跳重複、集合 +- 溢位:使用 64-bit + +## 測試案例 + +### 範例輸入輸出 +``` +Input: ... +Output: ... +Explanation: ... +``` + +### 邊界清單 +- [ ] 空陣列/空字串 +- [ ] 單一元素 / 全相同 +- [ ] 含負數/0/大數 +- [ ] 去重 +- [ ] 大資料壓力 + +## 複雜度分析 +- 最壞:時間 O(?)、空間 O(?) + +## 相關題目 / Follow-up +- + +## 學習筆記 +- 今天學到: +- 卡住與修正: +- 待優化: + +--- +**總結**:這題的核心在於 ______,適合練習 ______。 + diff --git a/problems/3005-count_elements_with_maximum_frequency/csharp/Program.cs b/problems/3005-count_elements_with_maximum_frequency/csharp/Program.cs new file mode 100644 index 0000000..267f26b --- /dev/null +++ b/problems/3005-count_elements_with_maximum_frequency/csharp/Program.cs @@ -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 frequencyMap = new Dictionary(); + + // 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!"); + } +} + diff --git a/problems/3005-count_elements_with_maximum_frequency/csharp/csharp.csproj b/problems/3005-count_elements_with_maximum_frequency/csharp/csharp.csproj new file mode 100644 index 0000000..9dbab49 --- /dev/null +++ b/problems/3005-count_elements_with_maximum_frequency/csharp/csharp.csproj @@ -0,0 +1,9 @@ + + + Exe + net8.0 + enable + enable + + + diff --git a/problems/3005-count_elements_with_maximum_frequency/go/main.go b/problems/3005-count_elements_with_maximum_frequency/go/main.go new file mode 100644 index 0000000..6102b55 --- /dev/null +++ b/problems/3005-count_elements_with_maximum_frequency/go/main.go @@ -0,0 +1,18 @@ +// LeetCode 3005: Count_elements_with_maximum_frequency +// 難度: Easy +// 日期: 2025-09-22 + +package main + +import "fmt" + +// TODO: 根據題意調整簽名 +func solve(nums []int) int { + return 0 +} + +func main() { + fmt.Printf("Hello LeetCode 3005!\n") + // TODO: 可加入簡單測試 +} + diff --git a/problems/3005-count_elements_with_maximum_frequency/test/SolutionTests.cs b/problems/3005-count_elements_with_maximum_frequency/test/SolutionTests.cs new file mode 100644 index 0000000..001d054 --- /dev/null +++ b/problems/3005-count_elements_with_maximum_frequency/test/SolutionTests.cs @@ -0,0 +1,24 @@ +// LeetCode 3005 單元測試(xUnit) + +using Xunit; + +public class SolutionTests { + private readonly Solution _s = new Solution(); + + [Fact] + public void Example1() { + // TODO: Arrange + // var input = new int[] { }; + // var expected = 0; + // Act + // var got = _s.Solve(input); + // Assert.Equal(expected, got); + Assert.True(true); + } + + [Fact] + public void EdgeCases() { + Assert.True(true); + } +} + diff --git a/problems/3005-count_elements_with_maximum_frequency/test/TestProject.csproj b/problems/3005-count_elements_with_maximum_frequency/test/TestProject.csproj new file mode 100644 index 0000000..e2d8b41 --- /dev/null +++ b/problems/3005-count_elements_with_maximum_frequency/test/TestProject.csproj @@ -0,0 +1,19 @@ + + + net8.0 + enable + false + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + diff --git a/problems/3005-count_elements_with_maximum_frequency/test/main_test.go b/problems/3005-count_elements_with_maximum_frequency/test/main_test.go new file mode 100644 index 0000000..29c5fb3 --- /dev/null +++ b/problems/3005-count_elements_with_maximum_frequency/test/main_test.go @@ -0,0 +1,12 @@ +// LeetCode 3005 單元測試(Go testing) +package main + +import "testing" + +func TestExample(t *testing.T) { + // TODO: input := []int{} + // got := solve(input) + // want := 0 + // if got != want { t.Fatalf("want %v got %v", want, got) } +} +