题解 | #查找兄弟单词#
查找兄弟单词
https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
# from collections import Counter def counter(word: str): cnt = [0 for _ in range(26)] for char in word: cnt[ord(char) - ord("a")] += 1 return cnt if __name__ == "__main__": line = list(input().strip().split()) n = int(line[0]) k = int(line[-1]) x = line[-2] words = list(line[1:-2]) bros = list() for word in words: if word != x and sorted(word) == sorted(x): bros.append(word) bros.sort() print(len(bros)) if len(bros) >= k: print(bros[k - 1])
算法之路 文章被收录于专栏
有关数据结构、算法等的文章