每日一题力扣451
作者:互联网
给定一个字符串,请将字符串里的字符按照出现的频率降序排列。
class Solution: def frequencySort(self, s: str) -> str: d={} res='' for i in s: d[i]=d.get(i,0)+1 d=sorted(d.items(),key=lambda k:-k[1])#字典排序 for i in d: for j in range(i[1]): res+=i[0] return res
标签:451,self,frequencySort,力扣,str,res,字符串,一题 来源: https://www.cnblogs.com/liuxiangyan/p/14530157.html