Returns the length of the longest sequence of identical digits found in num recursive

I had an assignement;

"Write a recursive static method that accepts a positive integer num and returns the length of the longest sequence of identical digits found in num."

This is the solution I did

public static int equalDigits (int num)
{
    return equalDigits(num,1,0);
}

private static int equalDigits (int num, int count, int max){ 
    if (num < 10)
        return 1;
    if (num/10%10 == num%10)
        count++;
    else
        count = 1;
    max = count > max ? count : max;
    return Math.max(max,equalDigits(num/10,count,max));
}

But my lecturer said it can be done without using helper method. I can't figured how exactly it's possible.



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)