You are viewing a single comment's thread. Return to all comments →
static long repeatedString(String s, long n) { int i = 0; long lCountA = 0, rCountA = 0; long sTimes = n / s.length(); long remainChars = n % s.length(); if(remainChars > 0){ for(; i < remainChars; i++){ if(s.charAt(i) == 'a') lCountA++; } } if(sTimes > 0){ for(; i < s.length(); i++){ if(s.charAt(i) == 'a') rCountA++; } } return sTimes * (rCountA + lCountA) + lCountA; }
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 →