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.
static long repeatedString(String s, long n) {
Matcher matcher = Pattern.compile(String.valueOf('a')).matcher(s);
int aInInput = 0;
while (matcher.find()) {
aInInput++;
}
long totalA = 0L;
if (s.equals("a")) {
return n;
} else {
totalA = totalA + ((n / s.length()) * aInInput);
for (int i = 0; i < (n % s.length()); i++) {
if (s.charAt(i) == 'a') {
totalA++;
}
}
}
return totalA;
}
Repeated String
You are viewing a single comment's thread. Return to all comments →