Skip to content

Commit a4fc5c0

Browse files
authored
feat: add cs solution to lc problem: No.1887 (#1984)
1 parent b10922c commit a4fc5c0

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ func reductionOperations(nums []int) int {
201201
}
202202
```
203203

204+
### **C#**
205+
206+
```cs
207+
public class Solution {
208+
public int ReductionOperations(int[] nums) {
209+
Array.Sort(nums);
210+
int ans = 0, up = 0;
211+
for (int i = 1; i < nums.Length; i++) {
212+
if (nums[i] != nums[i - 1]) {
213+
up++;
214+
}
215+
ans += up;
216+
}
217+
return ans;
218+
}
219+
}
220+
```
221+
204222
### **...**
205223

206224
```

solution/1800-1899/1887.Reduction Operations to Make the Array Elements Equal/README_EN.md

+18
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,24 @@ func reductionOperations(nums []int) int {
183183
}
184184
```
185185

186+
### **C#**
187+
188+
```cs
189+
public class Solution {
190+
public int ReductionOperations(int[] nums) {
191+
Array.Sort(nums);
192+
int ans = 0, up = 0;
193+
for (int i = 1; i < nums.Length; i++) {
194+
if (nums[i] != nums[i - 1]) {
195+
up++;
196+
}
197+
ans += up;
198+
}
199+
return ans;
200+
}
201+
}
202+
```
203+
186204
### **...**
187205

188206
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Solution {
2+
public int ReductionOperations(int[] nums) {
3+
Array.Sort(nums);
4+
int ans = 0, up = 0;
5+
for (int i = 1; i < nums.Length; i++) {
6+
if (nums[i] != nums[i - 1]) {
7+
up++;
8+
}
9+
ans += up;
10+
}
11+
return ans;
12+
}
13+
}

0 commit comments

Comments
 (0)