You are viewing a single comment's thread. Return to all comments →
This code is working
static long getNum(String n){ long num = 0; for(char c : n.toCharArray()) num += Character.digit(c, 10); return num; } static int superDigit(String n){ System.out.println(n); if(n.length() <= 1) return Integer.parseInt(n); return superDigit(String.valueOf(getNum(n))); } static int superDigit(String n, int k) { return superDigit(String.valueOf(k * getNum(n))); }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
This code is working