Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cs solution to lc problem: No.1814 #1997

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update README.md to lc problem: No.1814
  • Loading branch information
dev-mauli authored Nov 21, 2023
commit c74c20c1c1ad0ad63fab3b76b053a3026996dd27
30 changes: 30 additions & 0 deletions solution/1800-1899/1814.Count Nice Pairs in an Array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,36 @@ function countNicePairs(nums: number[]): number {
}
```

### **C#**

```cs
public class Solution {
public int CountNicePairs(int[] nums) {
Dictionary<int, int> cnt = new Dictionary<int, int>();
foreach (int x in nums) {
int y = x - Rev(x);
cnt[y] = cnt.GetValueOrDefault(y, 0) + 1;
}
int mod = (int)1e9 + 7;
long ans = 0;
foreach (int v in cnt.Values) {
ans = (ans + (long)v * (v - 1) / 2) % mod;
}
return (int)ans;
}

private int Rev(int x) {
int y = 0;
while (x > 0) {
y = y * 10 + x % 10;
x /= 10;
}
return y;
}
}
```


### **...**

```
Expand Down