diff --git a/.idea/.idea.Leetcode/.idea/workspace.xml b/.idea/.idea.Leetcode/.idea/workspace.xml
index 6fcef90..09d9488 100644
--- a/.idea/.idea.Leetcode/.idea/workspace.xml
+++ b/.idea/.idea.Leetcode/.idea/workspace.xml
@@ -42,6 +42,7 @@
299. Bulls and Cows/299. Bulls and Cows.csproj
3. Longest Substring Without Repeating Characters/3. Longest Substring Without Repeating Characters.csproj
344. Reverse String/344. Reverse String.csproj
+ 347. Top K Frequent Elements/347. Top K Frequent Elements.csproj
35. Search Insert Position/35. Search Insert Position.csproj
350. Intersection of Two Arrays II/350. Intersection of Two Arrays II.csproj
36. Valid Sudoku/36. Valid Sudoku.csproj
@@ -89,9 +90,11 @@
-
+
+
+
-
+
@@ -127,6 +130,7 @@
"keyToString": {
".NET Project.14. Longest Common Prefix.executor": "Run",
".NET Project.150. Evaluate Reverse Polish Notation.executor": "Run",
+ ".NET Project.347. Top K Frequent Elements.executor": "Run",
".NET Project.451. Sort Characters By Frequency.executor": "Run",
".NET Project.9. Palindrome Number.executor": "Run",
"ASKED_ADD_EXTERNAL_FILES": "true",
@@ -151,7 +155,7 @@
]
}
}]]>
-
+
@@ -908,6 +912,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1701,7 +1723,7 @@
-
+
diff --git a/347. Top K Frequent Elements/347. Top K Frequent Elements.csproj b/347. Top K Frequent Elements/347. Top K Frequent Elements.csproj
new file mode 100644
index 0000000..cf4697e
--- /dev/null
+++ b/347. Top K Frequent Elements/347. Top K Frequent Elements.csproj
@@ -0,0 +1,11 @@
+
+
+
+ Exe
+ net8.0
+ _347._Top_K_Frequent_Elements
+ enable
+ enable
+
+
+
diff --git a/347. Top K Frequent Elements/Program.cs b/347. Top K Frequent Elements/Program.cs
new file mode 100644
index 0000000..bc7878c
--- /dev/null
+++ b/347. Top K Frequent Elements/Program.cs
@@ -0,0 +1,4 @@
+using _347._Top_K_Frequent_Elements;
+
+var sol = new Solution();
+Console.WriteLine(string.Join(", ", sol.TopKFrequent([1,1,1,2,2,3], 2)));
\ No newline at end of file
diff --git a/347. Top K Frequent Elements/Solution.cs b/347. Top K Frequent Elements/Solution.cs
new file mode 100644
index 0000000..1d95825
--- /dev/null
+++ b/347. Top K Frequent Elements/Solution.cs
@@ -0,0 +1,13 @@
+namespace _347._Top_K_Frequent_Elements;
+
+public class Solution
+{
+ public int[] TopKFrequent(int[] nums, int k)
+ {
+ var dictionary = new Dictionary();
+ foreach (var num in nums)
+ if (!dictionary.TryAdd(num, 1))
+ dictionary[num]++;
+ return dictionary.OrderByDescending(kp=>kp.Value).Take(k).Select(kp=>kp.Key).ToArray();
+ }
+}
\ No newline at end of file
diff --git a/Leetcode.sln b/Leetcode.sln
index ce77058..01fd750 100644
--- a/Leetcode.sln
+++ b/Leetcode.sln
@@ -173,6 +173,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "9. Palindrome Number", "9.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "451. Sort Characters By Frequency", "451. Sort Characters By Frequency\451. Sort Characters By Frequency.csproj", "{CA2D97FB-8F9D-40C0-BCE6-CBF0528AE296}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "347. Top K Frequent Elements", "347. Top K Frequent Elements\347. Top K Frequent Elements.csproj", "{F4DE54A1-6881-445A-A6B6-2206293D2F2E}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -519,6 +521,10 @@ Global
{CA2D97FB-8F9D-40C0-BCE6-CBF0528AE296}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA2D97FB-8F9D-40C0-BCE6-CBF0528AE296}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA2D97FB-8F9D-40C0-BCE6-CBF0528AE296}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F4DE54A1-6881-445A-A6B6-2206293D2F2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F4DE54A1-6881-445A-A6B6-2206293D2F2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F4DE54A1-6881-445A-A6B6-2206293D2F2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F4DE54A1-6881-445A-A6B6-2206293D2F2E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE