public IList<int>TopKFrequent(int[] nums,int k){var res =newList<int>();var dict =newDictionary<int,int>();var bucket =newList<int>[nums.Length +1];foreach(var num in nums){if(!dict.ContainsKey(num))
dict.Add(num,0);
dict[num]++;}foreach(var item in dict){if(bucket[item.Value]==null)
bucket[item.Value]=newList<int>();
bucket[item.Value].Add(item.Key);}for(var i = bucket.Length -1; i >=0; i--){if(bucket[i]==null)continue;foreach(var item in bucket[i]){
res.Add(item);if(res.Count == k){return res;}}}return res;}
public IList<string>TopKFrequent(string[] words,int k){var res =newList<string>();var dict =newDictionary<string,int>();foreach(var w in words){if(!dict.ContainsKey(w)){
dict.Add(w,0);}
dict[w]++;}var bucket =newList<string>[words.Length];for(var i=0;i<bucket.Length;i++){
bucket[i]=newList<string>();}foreach(var w in dict){
bucket[w.Value].Add(w.Key);}var count =0;for(var i=bucket.Length-1;i>=0;i--){
bucket[i].Sort();foreach(var w in bucket[i]){
res.Add(w);
count++;if(count==k)return res;}}return res;}