You are viewing a single comment's thread. Return to all comments →
Java arithmatic approach:
public static long repeatedString(String s, long n) { long fullRpt = n / s.length(); int perStringA = 0; for (char c : s.toCharArray()) { if (c == 'a') perStringA++; } int remA = 0; int rem = (int) (n % s.length()); for (int i = 0; i < rem; i++) { if (s.charAt(i) == 'a') remA++; } return perStringA*fullRpt + remA; }
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 arithmatic approach: