diff --git a/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README.md b/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README.md index e6d0f1b64d06e..3c52de7cb6d3e 100644 --- a/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README.md +++ b/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README.md @@ -202,6 +202,27 @@ var eliminateMaximum = function (dist, speed) { }; ``` +### **C#** + +```cs +public class Solution { + public int EliminateMaximum(int[] dist, int[] speed) { + int n = dist.Length; + int[] times = new int[n]; + for (int i = 0; i < n; ++i) { + times[i] = (dist[i] - 1) / speed[i]; + } + Array.Sort(times); + for (int i = 0; i < n; ++i) { + if (times[i] < i) { + return i; + } + } + return n; + } +} +``` + ### **...** ``` diff --git a/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README_EN.md b/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README_EN.md index 5773e3029e240..5925a752b540b 100644 --- a/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README_EN.md +++ b/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/README_EN.md @@ -177,6 +177,27 @@ var eliminateMaximum = function (dist, speed) { }; ``` +### **C#** + +```cs +public class Solution { + public int EliminateMaximum(int[] dist, int[] speed) { + int n = dist.Length; + int[] times = new int[n]; + for (int i = 0; i < n; ++i) { + times[i] = (dist[i] - 1) / speed[i]; + } + Array.Sort(times); + for (int i = 0; i < n; ++i) { + if (times[i] < i) { + return i; + } + } + return n; + } +} +``` + ### **...** ``` diff --git a/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/Solution.cs b/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/Solution.cs new file mode 100644 index 0000000000000..be90a23b80105 --- /dev/null +++ b/solution/1900-1999/1921.Eliminate Maximum Number of Monsters/Solution.cs @@ -0,0 +1,16 @@ +public class Solution { + public int EliminateMaximum(int[] dist, int[] speed) { + int n = dist.Length; + int[] times = new int[n]; + for (int i = 0; i < n; ++i) { + times[i] = (dist[i] - 1) / speed[i]; + } + Array.Sort(times); + for (int i = 0; i < n; ++i) { + if (times[i] < i) { + return i; + } + } + return n; + } +}