Created
October 29, 2019 15:24
-
-
Save boriphuth/a698e3f37b2e37ef863ce4048ef5f798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
class Solution { | |
public int solution(int N) { | |
string bin = Convert.ToString(N, 2); | |
//Console.WriteLine(bin); | |
int gap = 0; | |
int maxGap = 0 ; | |
for (int i = 0; i < bin.Length; i++){ | |
if (bin[i] == '1'){ | |
if (gap > maxGap){ | |
maxGap = gap; | |
} | |
gap = 0; | |
} | |
else { | |
gap++; | |
} | |
} | |
return maxGap; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment