Group Anagrams

Medium

Topics
ArrayStringHash TableSorting

Given an array of strings strs, group the anagrams together. Return the groups in any order.

Example 1

Input:  strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]

Example 2

Input:  strs = [""]
Output: [[""]]

Constraints

  • 1 <= strs.length <= 10^4
  • 0 <= strs[i].length <= 100
  • strs[i] consists of lowercase English letters.
Run ⌘' · Submit ⌘⏎