File tree Expand file tree Collapse file tree 3 files changed +84
-0
lines changed
solution/1600-1699/1630.Arithmetic Subarrays Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Original file line number Diff line number Diff line change @@ -254,6 +254,36 @@ impl Solution {
254254}
255255```
256256
257+ ### ** C#**
258+
259+ ``` cs
260+ class Solution {
261+ public bool Check (int [] arr ) {
262+ Array .Sort (arr );
263+ int diff = arr [1 ] - arr [0 ];
264+ for (int i = 2 ; i < arr .Length ; i ++ ) {
265+ if (arr [i ] - arr [i - 1 ] != diff ) {
266+ return false ;
267+ }
268+ }
269+ return true ;
270+ }
271+
272+ public IList <bool > CheckArithmeticSubarrays (int [] nums , int [] l , int [] r ) {
273+ List < bool > ans = new List <bool >();
274+ for (int i = 0 ; i < l .Length ; i ++ ) {
275+ int [] arr = new int [r [i ] - l [i ] + 1 ];
276+ for (int j = 0 ; j < arr .Length ; j ++ ) {
277+ arr [j ] = nums [l [i ] + j ];
278+ }
279+ ans .Add (Check (arr ));
280+ }
281+ return ans ;
282+ }
283+ }
284+
285+ ```
286+
257287### ** ...**
258288
259289```
Original file line number Diff line number Diff line change @@ -234,6 +234,36 @@ impl Solution {
234234}
235235```
236236
237+ ### ** C#**
238+
239+ ``` cs
240+ class Solution {
241+ public bool Check (int [] arr ) {
242+ Array .Sort (arr );
243+ int diff = arr [1 ] - arr [0 ];
244+ for (int i = 2 ; i < arr .Length ; i ++ ) {
245+ if (arr [i ] - arr [i - 1 ] != diff ) {
246+ return false ;
247+ }
248+ }
249+ return true ;
250+ }
251+
252+ public IList <bool > CheckArithmeticSubarrays (int [] nums , int [] l , int [] r ) {
253+ List < bool > ans = new List <bool >();
254+ for (int i = 0 ; i < l .Length ; i ++ ) {
255+ int [] arr = new int [r [i ] - l [i ] + 1 ];
256+ for (int j = 0 ; j < arr .Length ; j ++ ) {
257+ arr [j ] = nums [l [i ] + j ];
258+ }
259+ ans .Add (Check (arr ));
260+ }
261+ return ans ;
262+ }
263+ }
264+
265+ ```
266+
237267### ** ...**
238268
239269```
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public bool Check ( int [ ] arr ) {
3+ Array . Sort ( arr ) ;
4+ int diff = arr [ 1 ] - arr [ 0 ] ;
5+ for ( int i = 2 ; i < arr . Length ; i ++ ) {
6+ if ( arr [ i ] - arr [ i - 1 ] != diff ) {
7+ return false ;
8+ }
9+ }
10+ return true ;
11+ }
12+
13+ public IList < bool > CheckArithmeticSubarrays ( int [ ] nums , int [ ] l , int [ ] r ) {
14+ List < bool > ans = new List < bool > ( ) ;
15+ for ( int i = 0 ; i < l . Length ; i ++ ) {
16+ int [ ] arr = new int [ r [ i ] - l [ i ] + 1 ] ;
17+ for ( int j = 0 ; j < arr . Length ; j ++ ) {
18+ arr [ j ] = nums [ l [ i ] + j ] ;
19+ }
20+ ans . Add ( Check ( arr ) ) ;
21+ }
22+ return ans ;
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments