# 题目描述

Given a string, sort it in decreasing order based on the frequency of characters.

# 例子

Example 1:

Input:
"tree"

Output:
"eert"

Explanation:
'e' appears twice while 'r' and 't' both appear once.
So 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer.


Example 2:

Input:
"cccaaa"

Output:
"cccaaa"

Explanation:
Both 'c' and 'a' appear three times, so "aaaccc" is also a valid answer.
Note that "cacaca" is incorrect, as the same characters must be together.


Example 3:

Input:
"Aabb"

Output:
"bbAa"

Explanation:
"bbaA" is also a valid answer, but "Aabb" is incorrect.
Note that 'A' and 'a' are treated as two different characters.


# 代码

class Solution(object):
def frequencySort(self, s):
"""
:type s: str
:rtype: str
"""
import collections
c = collections.Counter(s)
tup = []
for key in c:
tup.append((key, c[key]))
tup.sort(key = lambda x:x[1], reverse = True)
res = ""
for t in tup:
res += t[0] * t[1]
return res


09-22 1569

03-11 155

05-26 856

05-18 7

02-07 3067

12-31 319

10-06 1163

03-30 9

09-16 1831

03-06 1111

12-01 7

09-23 51

02-27 1641

07-27 88

04-14 59万+

03-13 15万+

03-04 14万+

03-08 2万+

04-25 6万+

03-10 13万+

03-10 18万+

03-12 11万+

03-13 11万+

03-18 9919

03-19 8万+

03-19 3万+

03-22 4万+

03-23 4万+

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-29 21万+

03-29 10万+

03-30 16万+

05-31 6318

05-31 1万+

04-02 1万+

04-02 5664

04-02 4万+

04-06 1万+

04-06 7万+

04-09 8万+

04-09 2万+

05-17 8574

04-11 3万+

04-15 6万+

04-18 4万+

04-20 4万+

04-24 3万+

05-01 6433

05-03 1万+

05-16 5万+

05-06 1万+

05-07 2747

05-07 1万+

05-08 4万+

05-10 3312

05-14 6528

05-16 3602

05-16 1万+

05-17 5085

05-30 382

05-20 1006

05-18 2259

05-18 8433

05-27 1452

05-18 3621

05-28 1292

05-19 1万+

05-19 1943

05-21 7606

05-21 7632

05-27 5211

05-25 5398

05-23 6557

05-28 1705

05-23 1167

05-23 3074

05-24 8514

#### java代码30行实现用我爱你重绘女朋友美照（我对你的爱，在每一个字里行间）

©️2019 CSDN 皮肤主题: 创作都市 设计师: CSDN官方博客