Posted on 2022-12-03 14:32
Uriel 阅读(33)
评论(0) 编辑 收藏 引用 所属分类:
闲来无事重切Leet Code 、
大水题
对一串字符串中的每个字符按照出现次数重排序,出现次数相同的话先后顺序随意,e.g.,
Input: s = "Aabb"
Output: "bbAa"
直接用python的Counter的most_common按出现次数多到少排序字符
1 #451
2 #Runtime: 133 ms
3 #Memory Usage: 15.9 MB
4
5 class Solution(object):
6 def frequencySort(self, s):
7 """
8 :type s: str
9 :rtype: str
10 """
11 return ''.join(ch*n for ch, n in Counter(s).most_common())