Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
问题陈述:给定一组 k 个字符串,每个长度为 n。您必须一起输出这组字谜。字谜就像例如 atm - mat ,like-kile。
只需对单词的字母进行排序即可获得特定于字谜的签名。例如,在 Python 中,
sig = ''.join(sorted(word))
并将dictwithsig作为键,值是具有该签名的单词列表(defaultdict(list)适用于此)。当然,您可以使用任何具有排序能力的语言以及其值可以是列表或向量的关联数组来执行此操作;-)。
dict
sig
defaultdict(list)