You are viewing a single comment's thread. Return to all comments →
you can avoid doing two for loops by doing something along the lines of:
int max = 0; int count = 0; for (int v : a) { if (v > max) {max = v; count = 1;} else if (v == max) count++; } return count;
You can avoid iterating over the collection twice
Seems like cookies are disabled on this browser, please enable them to open this website
Birthday Cake Candles
You are viewing a single comment's thread. Return to all comments →
you can avoid doing two for loops by doing something along the lines of:
You can avoid iterating over the collection twice