You are viewing a single comment's thread. Return to all comments →
Java 15
class Result { private static final IntPredicate isA = c -> c == 'a'; public static long repeatedString(String s, long n) { long times = n / s.length(); long remainingChars = n % s.length(); long count = s.chars().filter(isA).count(); count*=times; count += s.substring(0, (int) remainingChars).chars().filter(isA).count(); return count; } }
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 →
Java 15