We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Java 8 solution. Passed all cases. Make sure you are storing the sum of the digits as a Long.
publicstaticintsuperDigit(Stringn,intk){// Write your code hereif(n.length()==1){returnInteger.parseInt(n);}else{longsum=0;for(inti=0;i<n.length();i++){sum+=n.charAt(i)-'0';}sum=sum*k;returnsuperDigit(Long.toString(sum),1);}}
Cookie support is required to access HackerRank
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 →
Java 8 solution. Passed all cases. Make sure you are storing the sum of the digits as a Long.