Checking if two strings are permutations of each other

前端 未结 30 1051
感情败类
感情败类 2020-12-05 08:19

How to determine if two strings are permutations of each other

30条回答
  •  鱼传尺愫
    2020-12-05 08:52

    1. Sort the 2 strings by characters and compare if they're the same (O(n log n) time, O(n) space), or
    2. Tally the character frequency of the 2 strings and compare if they're the same (O(n) time, O(n) space).

提交回复
热议问题