Codility – Lesson 1 Iterations – BinaryGap
プログラミング能力を評価するオンラインテスト、Codilityで、Lesson 1 Iterations – BinaryGapに回答しました。
問題と結果画面
100%の評価。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
using System; class Solution { public int solution(int N) { int length = 0; string binary = System.Convert.ToString(N, 2); string[] values = binary.Split ('1'); for(int i = 0; i < values.Length - 1; i++) { if(length < values [i].Length) { length = values [i].Length; } } return length; } } |