Codility – Lesson 2 Arrays – CyclicRotation
プログラミング能力を評価するオンラインテスト、Codilityで、Lesson 2 Arrays – CyclicRotationに回答しました。
問題と結果画面
100%の評価。
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 |
using System; using System.Collections.Generic; class Solution { public int[] solution(int[] A, int K) { if (A.Length < 1) return A; List<int> list = new List<int> (); foreach(int a in A) { list.Add (a); } for (int i = 0; i < K; i++) { int last = list [list.Count - 1]; list.RemoveAt (list.Count - 1); list.Insert (0, last); } for (int i = 0; i < A.Length; i++) { A[i] = list[i]; } return A; } } |