Most frequent character · 出现最多的字符
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
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.
中文
出现最多的字符
返回非空 String 中出现次数最多的字符。如果两个字符并列,返回最先出现的那个。一个简单的做法:对每个字符,数出它出现的次数,并保留目前最优的 —— 用严格的 >,这样并列时保留较早的那个字符。
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. · 完成 mostFrequentChar(String s),返回出现次数最多的字符。并列时返回最先出现的那个。假设 s 非空。
Click Run to see the output here. · 点击“运行”查看此处输出。