You are viewing a single comment's thread. Return to all comments →
I think we could avoid one loop
static long repeatedString(String s, long n) { String sh = s.replaceAll ("[^a]", ""); long ost = n%s.length(); long qty = ((n - ost)/ s.length())*sh.length(); for (int i = 0; i < ost; i++) { if (s.charAt(i) == 'a') { qty++; } } return qty; }
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 →
I think we could avoid one loop