Skip to content

Instantly share code, notes, and snippets.

@boriphuth
Created October 29, 2019 15:24
Show Gist options
  • Save boriphuth/a698e3f37b2e37ef863ce4048ef5f798 to your computer and use it in GitHub Desktop.
Save boriphuth/a698e3f37b2e37ef863ce4048ef5f798 to your computer and use it in GitHub Desktop.
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