finding if two words are anagrams of each other

后端 未结 22 1294
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 14:51

I am looking for a method to find if two strings are anagrams of one another.

Ex: string1 - abcde
string2 - abced
Ans = true
Ex: string1 - abcde
string2 - ab         


        
22条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 15:25

    Well you can probably improve the best case and average case substantially just by checking the length first, then a quick checksum on the digits (not something complex, as that will probably be worse order than the sort, just a summation of ordinal values), then sort, then compare.

    If the strings are very short the checksum expense will be not greatly dissimilar to the sort in many languages.

提交回复
热议问题