49_Group Anagrams
Level: medium
Tag: string, hash table
Question
Idea
Complexity 1 (with sort)
Time Complexity: , where
n
is the length ofstrs
, andk
is the maximum length of a string instrs
. The outer loop has complexity as we iterate through each string. Then, we sort each string in time.Space Complexity: , the total information content stored in
ans
.
Complexity 2 (without sort, use count table)
Time Complexity: , where
n
is the length ofstrs
, andk
is the maximum length of a string instrs
. Counting each string is linear in the size of the string, and we count every string.Space Complexity: , the total information content stored in
ans
.
Solution 1 (with sort)
Solution 2 (without sort, use count table)
Last updated