You are viewing a single comment's thread. Return to all comments →
2 for loops is kind of unneeded here. Here's a refactor (in C#): int As = 0; int modAs = 0;
for(int i = 0; i < s.Length; i++) { if(s[i] == 'a') { As++; if(i < (n % s.Length)) modAs++; } } return As * (n/s.Length) + modAs;
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 →
2 for loops is kind of unneeded here. Here's a refactor (in C#): int As = 0; int modAs = 0;