You are viewing a single comment's thread. Return to all comments →
Here is recursive solution
static int superDigit(String n, int k) { long num = 0; for(int i=0; i<n.length(); i++) { num += Integer.parseInt(n.charAt(i)+""); } num = helper(num*k); int num2 = (int) num; return num2; } private static long helper(long n) { if(n<10) { return n; } else { int num = 0; while(n>0) { num += n % 10; n = n/10; } return helper(num); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
Here is recursive solution