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.
static int calculateBinary(int n)
{
int temp=0;
int max=0;
for ( int i=0; n > 1; i++)
{
if (n % 2 == 1)
{
temp++;
}
else
{
max = Math.max(max,temp);
temp = 0;
}
n = n / 2;
}
if (n ==1)
temp++;
max = Math.max(max,temp);
return max;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 10: Binary Numbers
You are viewing a single comment's thread. Return to all comments →
Same logic but just wanted to simplify it more:
}