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) {
char[] chrIn = s.toCharArray();
int i = 0;
long max = 0;
long quo = n / chrIn.length;
long rem = n % chrIn.length;
while (i < chrIn.length) {
if (chrIn[i] == 'a') {
max++;
}
i++;
}
i = 0;
max = max * quo;
while (i < rem) {
if (chrIn[i] == 'a') {
max++;
}
i++;
Repeated String
You are viewing a single comment's thread. Return to all comments →
try this
static long repeatedString(String s, long n) { char[] chrIn = s.toCharArray(); int i = 0; long max = 0; long quo = n / chrIn.length; long rem = n % chrIn.length; while (i < chrIn.length) { if (chrIn[i] == 'a') { max++; } i++; } i = 0; max = max * quo; while (i < rem) { if (chrIn[i] == 'a') { max++; } i++;