Codility – Lesson 3 Time Complexity – PermMissingElem
プログラミング能力を評価するオンラインテスト、Codilityで、Lesson 3 Time Complexity – PermMissingElemに回答しました。
問題と結果画面
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 |
using System; class Solution { public int solution(int[] A) { System.Array.Sort (A); int count = 0; for(int i = 0; i < A.Length; i++) { bool isFound = false; count = i + 1; if(A[i] == count) { isFound = true; continue; } if(!isFound) return count; } return count + 1; } } |