-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathCyclicRotation_2.cs
More file actions
41 lines (31 loc) · 794 Bytes
/
CyclicRotation_2.cs
File metadata and controls
41 lines (31 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Linq;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution
{
public int[] solution(int[] A, int K)
{
// write your code in C# 6.0 with .NET 4.5 (Mono)
int N = A.Length;
if ((N==0) || (K==0) || (K==N))
{
return A;
}
int i;
if (K > N)
{
i = K % N;
}
else
{
i = K;
}
var A1 = A.Skip(N-i).Take(i);
var A2 = A.Skip(0).Take(N-i);
int[] B = A1.Concat(A2).ToArray();
return B;
}
}