Most frequent character · Caractère le plus fréquent
Most frequent character
Return the character that appears most often in a non-empty String. If two characters tie, return the one that appears earliest. A simple approach: for each character, count how many times it occurs, and keep the best so far — using a strict > so a tie keeps the earlier character.
Caractère le plus fréquent
Retournez le caractère qui apparaît le plus souvent dans un String non vide. Si deux caractères font match, retournez celui qui apparaît en premier. Une approche simple : pour chaque caractère, comptez combien de fois il apparaît, et gardez le meilleur jusqu'ici — en utilisant un strict > pour qu'une égalité conserve le caractère précédent.
Complete mostFrequentChar(String s) so it returns the most-common character. On a tie, return the one that appears earliest. Assume s is not empty. · Complétez mostFrequentChar(String s) pour qu'il retourne le caractère le plus fréquent. En cas d'égalité, retournez celui qui apparaît en premier. Supposez que s n'est pas vide.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.