From 2f8ee82cea23f7f78e18e636894f8f3a9e95c906 Mon Sep 17 00:00:00 2001 From: Pandurang Lad Date: Tue, 21 Nov 2023 11:37:00 -0600 Subject: [PATCH 1/4] feat: add cs solution to lc problem: No.1814 --- .../Solution.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 solution/1800-1899/1814.Count Nice Pairs in an Array/Solution.cs diff --git a/solution/1800-1899/1814.Count Nice Pairs in an Array/Solution.cs b/solution/1800-1899/1814.Count Nice Pairs in an Array/Solution.cs new file mode 100644 index 0000000000000..45a7d349c100f --- /dev/null +++ b/solution/1800-1899/1814.Count Nice Pairs in an Array/Solution.cs @@ -0,0 +1,24 @@ +public class Solution { + public int CountNicePairs(int[] nums) { + Dictionary cnt = new Dictionary(); + 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; + } +} From b825567f2491112c62d98a5a5c7afe14a7b80821 Mon Sep 17 00:00:00 2001 From: Pandurang Lad Date: Tue, 21 Nov 2023 11:40:40 -0600 Subject: [PATCH 2/4] Update README_EN.md to lc problem: No.1814 --- .../README_EN.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/solution/1800-1899/1814.Count Nice Pairs in an Array/README_EN.md b/solution/1800-1899/1814.Count Nice Pairs in an Array/README_EN.md index 3f4a53da9142d..c2033412e16f1 100644 --- a/solution/1800-1899/1814.Count Nice Pairs in an Array/README_EN.md +++ b/solution/1800-1899/1814.Count Nice Pairs in an Array/README_EN.md @@ -314,6 +314,35 @@ function countNicePairs(nums: number[]): number { } ``` +### **C#** + +```cs +public class Solution { + public int CountNicePairs(int[] nums) { + Dictionary cnt = new Dictionary(); + 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; + } +} +``` + ### **...** ``` From c74c20c1c1ad0ad63fab3b76b053a3026996dd27 Mon Sep 17 00:00:00 2001 From: Pandurang Lad Date: Tue, 21 Nov 2023 11:43:22 -0600 Subject: [PATCH 3/4] Update README.md to lc problem: No.1814 --- .../README.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md b/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md index 3fe311242d8fd..b010b49c225f8 100644 --- a/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md +++ b/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md @@ -322,6 +322,36 @@ function countNicePairs(nums: number[]): number { } ``` +### **C#** + +```cs +public class Solution { + public int CountNicePairs(int[] nums) { + Dictionary cnt = new Dictionary(); + 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; + } +} +``` + + ### **...** ``` From d3e2e54dfa041e1604ce51bbfe6f868dd64e338d Mon Sep 17 00:00:00 2001 From: dev-mauli Date: Tue, 21 Nov 2023 17:44:27 +0000 Subject: [PATCH 4/4] style: format code and docs with prettier --- solution/1800-1899/1814.Count Nice Pairs in an Array/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md b/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md index b010b49c225f8..cbca81f3085cf 100644 --- a/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md +++ b/solution/1800-1899/1814.Count Nice Pairs in an Array/README.md @@ -351,7 +351,6 @@ public class Solution { } ``` - ### **...** ```