You are viewing a single comment's thread. Return to all comments →
Your solution is really good. I would suggest even less variables, like:
public class Solution {
public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int s=0, t=0;
while(n>0) { if(n%2==1) { s++; if(s>=t) t=s; } else{ s=0; } n/=2; } System.out.println(t); }
}
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 →
Your solution is really good. I would suggest even less variables, like:
public class Solution {
public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int s=0, t=0;
}