We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 10: Binary Numbers
Day 10: Binary Numbers
Sort by
recency
|
2820 Discussions
|
Please Login in order to post a comment
I started off using the built-in bin() function, but it felt like the point was to do it myself, so I made user_bin to replicate it.
python 3
def base2(n):
Pyhton
n = int(input())
binary_representation = bin(n)[2:]
consecutive_ones = binary_representation.split('0')
max_consecutive_ones = max(len(group) for group in consecutive_ones)
print(max_consecutive_ones)
My C# solution
public static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine().Trim());