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.
int result=0;
int temp=0;
int n = Integer.parseInt(bufferedReader.readLine().trim());
for(int i=31; i>=0; i--){
int k = n>>i;
if((k&1)>0){
temp++;
result=Math.max(result, temp);
}else {
temp=0;
}
}
System.out.println(result);
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 →
//JAVA
int result=0; int temp=0; int n = Integer.parseInt(bufferedReader.readLine().trim()); for(int i=31; i>=0; i--){ int k = n>>i; if((k&1)>0){ temp++; result=Math.max(result, temp); }else { temp=0; }
System.out.println(result);