What is an easy way to tell if a list of words are anagrams of each other?

前端 未结 10 2002
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 18:38

How would you list words that are anagrams of each other?

I was asked this question when I applied for my current job.

orchestra can be rearrang

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 19:13

    The following algorithm should work:

    1. Sort the letters in each word.

    2. Sort the sorted lists of letters in each list.

    3. Compare each element in each list for equality.

提交回复
热议问题