Skip to content

Instantly share code, notes, and snippets.

@dzsquared
Created December 31, 2016 00:52
Show Gist options
  • Save dzsquared/909c8b669b498211914283470231ee54 to your computer and use it in GitHub Desktop.
Save dzsquared/909c8b669b498211914283470231ee54 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
static void Main(String[] args) {
int n = Convert.ToInt32(Console.ReadLine());
string thebinary = Convert.ToString(n, 2);
char[] binaryArray = thebinary.ToCharArray();
int consecutiveones = 0;
int maxconsec = 0;
for(int j = 0; j < thebinary.Length; j++) {
//Console.WriteLine(binaryArray[j]);
if(binaryArray[j]=='1') {
consecutiveones++;
//Console.WriteLine(consecutiveones);
if(consecutiveones > maxconsec) {
maxconsec = consecutiveones;
}
} else {
consecutiveones = 0;
}
}
Console.WriteLine(maxconsec);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment