You are viewing a single comment's thread. Return to all comments →
cpp soln
int superDigit(string n, int k) { long long sum=0; for (int i = 0; i < n.length(); i++) { char c = n[i]; int l = k * (c - '0'); sum += l; } n = to_string(sum); while(n.length()!=1){ long long sum=0; for (int i = 0; i < n.length(); i++) { char c = n[i]; long long l = 1 * (c - '0'); sum += l; } n = to_string(sum); } return n[0] - '0'; }
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 →
cpp soln