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 count(String s, long n) {
long numOfS = n/s.length();
long rest = n % s.length();
if(!s.contains("a")) return 0;
return s.length()>n? aCounter(s, rest)
: numOfS*aCounter(s, s.length()) + aCounter(s, rest);
}
private static long aCounter(String s, long end) {
int a=0;
for (int i = 0; i < end; i++) {
if (s.charAt(i) == 'a') a++;
}
return a;
}
Repeated String
You are viewing a single comment's thread. Return to all comments →
Java Solution