解Leetcode 451. Sort Characters By Frequency.兩個重點,一是可用陣列就不用hash table(C++ unordered_map)來計數,二是排序的元素很少,可以練習各種排序法,用sort,自製radix sort,用max heap(C++ priority_queue)
Python C++採陣列排序速解字串問題Leetcode 451 Sort Characters By Frequency
1. 頻率計數儲存在freq中
2. 使用陣列 freq_c`迭代來收集 ['0', 'z'] 的資訊 (freq[c-'0'], c)
3. 使用 sort 依照 greater 順序對 freq_c 進行排序
4. 使用字串函數來完成工作並傳回 ans
----
1. The frequency count is stored in freq
2. Use array freq_c` iteration to collect information of ['0', 'z'] (freq[c-'0'], c)
3. Use sort to sort freq_c in greater order
4. Use string functions to do the work and return ans
[codes on Leetcode]https://leetcode.com/problems/sort-characters-by-frequency/solutions/4689181/just-arrays-3-kinds-of-sortings-no-hash-table-0ms-beats-100/
[Leetcode playList]https://www.youtube.com/watch?v=FrnktWsWFeQ&list=PLYRlUBnWnd5IdDHk2BjqXwesydU17z_xk
[Dynamic Programming Playlist]https://www.youtube.com/watch?v=30yq3fmE6E8&list=PLYRlUBnWnd5K_XYUesV9oc6M9ONXII61T
沒有留言:
張貼留言