49. Group Anagrams
# Medium
Solution:
traverse all elements of strs
sort each word by letters
add to hashmap, the words composed with same letters will be mapped to same key-item
covert to
result
list
list.sort()
change the list, sorted(list)
doesn't change the list.
list.reverse()
change the list, reversed(list)
doesn't change the list.
sorted(string)
converts string to a list.
separator.join(list)
means convert list to a string combining by separator. For example, "".join(['a', 'b', 'c']) = "abc".
Last updated
Was this helpful?