You are viewing a single comment's thread. Return to all comments →
Leave loops for JDK:
static long repeatedString(String s, long n) { long canPlace = n / s.length(); long missingPart = n % s.length(); long qtyPerString = s.chars().filter(ch -> ch == 'a').count(); long missingChars = (missingPart > 0) ? s.substring(0, (int)missingPart).chars().filter(ch -> ch == 'a').count() : 0; return (canPlace * qtyPerString) + missingChars; }
Seems like cookies are disabled on this browser, please enable them to open this website
Repeated String
You are viewing a single comment's thread. Return to all comments →
Leave loops for JDK: