You are viewing a single comment's thread. Return to all comments →
You can simplify it like this:
int max=ar[0]; int count=0; for(int i=0;imax){ max=ar[i]; count = 1; //Reinitialize count if you found a new max }
else if(ar[i]==max){ count++; }
} return count;
I this case you are traversing the vector only once.
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 simplify it like this:
int max=ar[0]; int count=0; for(int i=0;imax){ max=ar[i]; count = 1; //Reinitialize count if you found a new max }
} return count;
I this case you are traversing the vector only once.