#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# return topK string
# @param strings string字符串一维数组 strings
# @param k int整型 the k
# @return string字符串二维数组
#
class Solution:
def topKstrings(self , strings: List[str], k: int) -> List[List[str]]:
res={}
rel=[]
# write code here
for string in strings:
if string in res:
res[string]+=1
else:
res[string]=1
for re in res.keys():
rel.append([re,res[re]])
def myfun(e):
return -e[1],e[0]
rel.sort(key=(myfun))
return rel[0:k]
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# return topK string
# @param strings string字符串一维数组 strings
# @param k int整型 the k
# @return string字符串二维数组
#
class Solution:
def topKstrings(self , strings: List[str], k: int) -> List[List[str]]:
res={}
rel=[]
# write code here
for string in strings:
if string in res:
res[string]+=1
else:
res[string]=1
for re in res.keys():
rel.append([re,res[re]])
def myfun(e):
return -e[1],e[0]
rel.sort(key=(myfun))
return rel[0:k]