451. Sort Characters By Frequency
题目来源:
https://leetcode.com/problems/sort-characters-by-frequency/
自我感觉难度/真实难度:
题意:
分析:
自己的代码:
代码效率/结果:
优秀代码:
class Solution: def frequencySort(self, s): """ :type s: str :rtype: str """ count=collections.Counter(s).most_common() res='' for c,n in count: res+=c*n return res
代码效率/结果:
Runtime: 44 ms, faster than 94.63% of Python3 online submissions for Sort Characters By Frequency.
自己优化后的代码:
反思改进策略:
1.有两个函数使用不熟练,一个是Counter(list),另一个是most_comon函数。具体解释:http://www.pythoner.com/205.html
写题时间时长:
2019年1月22号,1小时~