国产探花免费观看_亚洲丰满少妇自慰呻吟_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        """


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 杭锦后旗| 闻喜县| 岑巩县| 郑州市| 德保县| 西乡县| 亳州市| 麟游县| 凤凰县| 扎囊县| 九江市| 祁连县| 青川县| 临夏市| 铁岭市| 玉溪市| 麟游县| 拉孜县| 株洲县| 封丘县| 眉山市| 郯城县| 子洲县| 界首市| 奉新县| 象山县| 二手房| 年辖:市辖区| 顺义区| 凤庆县| 泗水县| 桃江县| 同德县| 延安市| 探索| 库尔勒市| 建昌县| 桑日县| 德惠市| 东源县| 江陵县|