You are viewing a single comment's thread. Return to all comments →
You won't need to run for loop twice in else case using this code. Time Complexity will decrease
int i = 0, count = 0, count1 = 0; if(n%s.size()==0){ for(int i = 0; i<s.size(); i++){ if(s.at(i)=='a'){ count++; } } return n/s.size()*count; } else{ for(int i = 0; i<s.size(); i++){ if(s.at(i)=='a'){ count++; if(i<n%s.size()){ count1++; } } } return (n/s.size()*count)+count1; } }
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 →
You won't need to run for loop twice in else case using this code. Time Complexity will decrease