From cafe4ad13db22047d965c6d632a3657c527d7f9e Mon Sep 17 00:00:00 2001 From: Pandurang Lad Date: Thu, 23 Nov 2023 06:29:47 -0600 Subject: [PATCH 1/3] feat: add cs solution to lc problem: No.1630 --- .../1630.Arithmetic Subarrays/Solution.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 solution/1600-1699/1630.Arithmetic Subarrays/Solution.cs diff --git a/solution/1600-1699/1630.Arithmetic Subarrays/Solution.cs b/solution/1600-1699/1630.Arithmetic Subarrays/Solution.cs new file mode 100644 index 0000000000000..22f2e09d06cac --- /dev/null +++ b/solution/1600-1699/1630.Arithmetic Subarrays/Solution.cs @@ -0,0 +1,24 @@ +class Solution { + public bool Check(int[] arr) { + Array.Sort(arr); + int diff = arr[1] - arr[0]; + for (int i = 2; i < arr.Length; i++) { + if (arr[i] - arr[i - 1] != diff) { + return false; + } + } + return true; + } + + public IList CheckArithmeticSubarrays(int[] nums, int[] l, int[] r) { + List ans = new List(); + for (int i = 0; i < l.Length; i++) { + int[] arr = new int[r[i] - l[i] + 1]; + for (int j = 0; j < arr.Length; j++) { + arr[j] = nums[l[i] + j]; + } + ans.Add(Check(arr)); + } + return ans; + } +} From c4b6ef1ce0fecb658f4d96f94b385cf2bf7bccb9 Mon Sep 17 00:00:00 2001 From: Pandurang Lad Date: Thu, 23 Nov 2023 06:31:07 -0600 Subject: [PATCH 2/3] Update README_EN.md to lc problem: No.1424 --- .../1630.Arithmetic Subarrays/README_EN.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/solution/1600-1699/1630.Arithmetic Subarrays/README_EN.md b/solution/1600-1699/1630.Arithmetic Subarrays/README_EN.md index 8430c942d4096..de58fb13e664a 100644 --- a/solution/1600-1699/1630.Arithmetic Subarrays/README_EN.md +++ b/solution/1600-1699/1630.Arithmetic Subarrays/README_EN.md @@ -234,6 +234,36 @@ impl Solution { } ``` +### **C#** + +```cs +class Solution { + public bool Check(int[] arr) { + Array.Sort(arr); + int diff = arr[1] - arr[0]; + for (int i = 2; i < arr.Length; i++) { + if (arr[i] - arr[i - 1] != diff) { + return false; + } + } + return true; + } + + public IList CheckArithmeticSubarrays(int[] nums, int[] l, int[] r) { + List ans = new List(); + for (int i = 0; i < l.Length; i++) { + int[] arr = new int[r[i] - l[i] + 1]; + for (int j = 0; j < arr.Length; j++) { + arr[j] = nums[l[i] + j]; + } + ans.Add(Check(arr)); + } + return ans; + } +} + +``` + ### **...** ``` From d7d96f1ac3c28597eeb4252a01dc21c3f695a9f8 Mon Sep 17 00:00:00 2001 From: Pandurang Lad Date: Thu, 23 Nov 2023 06:33:06 -0600 Subject: [PATCH 3/3] Update README.md to lc problem: No.1630 --- .../1630.Arithmetic Subarrays/README.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/solution/1600-1699/1630.Arithmetic Subarrays/README.md b/solution/1600-1699/1630.Arithmetic Subarrays/README.md index 993645d40fe4f..a9d24fd93a762 100644 --- a/solution/1600-1699/1630.Arithmetic Subarrays/README.md +++ b/solution/1600-1699/1630.Arithmetic Subarrays/README.md @@ -254,6 +254,36 @@ impl Solution { } ``` +### **C#** + +```cs +class Solution { + public bool Check(int[] arr) { + Array.Sort(arr); + int diff = arr[1] - arr[0]; + for (int i = 2; i < arr.Length; i++) { + if (arr[i] - arr[i - 1] != diff) { + return false; + } + } + return true; + } + + public IList CheckArithmeticSubarrays(int[] nums, int[] l, int[] r) { + List ans = new List(); + for (int i = 0; i < l.Length; i++) { + int[] arr = new int[r[i] - l[i] + 1]; + for (int j = 0; j < arr.Length; j++) { + arr[j] = nums[l[i] + j]; + } + ans.Add(Check(arr)); + } + return ans; + } +} + +``` + ### **...** ```