Codility – Lesson 6 Sorting – MaxProductOfThree
プログラミング能力を評価するオンラインテスト、Codilityで、Lesson 6 Sorting – MaxProductOfThreeに回答しました。
問題と結果画面
100%の評価。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
using System; using System.Linq; class Solution { public int solution(int[] A) { int N = A.Length; // Array.Sort(A); // Array.Reverse(A); A = A.OrderByDescending(c => c).ToArray(); // for(int i = 0; i < A.Length; i++) // { // Console.WriteLine("A[" + i + "] : " + A[i]); // } // -1 * -1 = 1; return Math.Max(A[0] * A[1] * A[2], A[0] * A[N-1] * A[N-2]); } } |