Recursive Digit Sum

  • + 0 comments

    There is no recursion here, checkout my 3 line solution:

    public static int superDigit(String n, int k) {
            BigInteger num=new BigInteger(n);
            int rem=  num.remainder(new BigInteger("9")).multiply(new BigInteger(k+"")).intValue();
       
        return rem%9==0?9: rem%9;
        }