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

前端 未结 10 1975
爱一瞬间的悲伤
爱一瞬间的悲伤 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:33

    1. compare length (if not equal, not a chance)
    2. make a bit vector of the length of the strings
    3. for each char in the first string find occurrences of it in the second
    4. set the bit for the first unset occurrence
    5. if you can find one stop with fail

提交回复
热议问题