• + 1 comment

    Stack stack=new Stack(); int count=1,i=-1,max=0; while(n!=0) { stack.push(n%2); n=n/2; } while(!stack.isEmpty()) { if(stack.peek()==i) { count++; }

            if(max<count)
            {
                max=count;
            }
            i=stack.peek();
    
            if(i==0)
            {
                count=1;
            }
            stack.pop();
        }