国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

【LeetCode】451. Sort Characters By Frequency【M】【68】

2019-11-08 02:33:55
字體:
來源:轉載
供稿:網友

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.

Subscribe to see which companies asked this question.對python來說 就是dcit的排序問題

class Solution(object):    def frequencySort(self, s):        d = {}                for i in s:            d[i] = d.get(i,0) + 1                    l = sorted(d.iteritems(),key = lambda k:k[1],reverse = True)                res = ''        for (k,v) in l:            res += k * v        return res                """        :type s: str        :rtype: str        """


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 舟山市| 雷波县| 鞍山市| 科技| 陈巴尔虎旗| 剑阁县| 汉寿县| 邮箱| 怀宁县| 宁蒗| 望都县| 慈溪市| 聂拉木县| 连南| 德令哈市| 手机| 沙坪坝区| 罗源县| 巴塘县| 凌海市| 新邵县| 保德县| 建德市| 定安县| 稷山县| 陇南市| 镇赉县| 新疆| 浠水县| 霍城县| 个旧市| 永顺县| 通榆县| 徐水县| 洛浦县| 滨海县| 绩溪县| 宿松县| 潜江市| 屏山县| 突泉县|