Python collections.Counter(s) 统计字符串s中各个字符的个数 s = "loveleetcode" # build hash map : character and how often it appears count = collections.Counter(s) 结果: