Nav: << previous: 48.旋转图像 | next: 50.Pow(x, n) >>


Description

tab: English
 
<p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
 
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
 
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">strs = [&quot;eat&quot;,&quot;tea&quot;,&quot;tan&quot;,&quot;ate&quot;,&quot;nat&quot;,&quot;bat&quot;]</span></p>
 
<p><strong>Output:</strong> <span class="example-io">[[&quot;bat&quot;],[&quot;nat&quot;,&quot;tan&quot;],[&quot;ate&quot;,&quot;eat&quot;,&quot;tea&quot;]]</span></p>
 
<p><strong>Explanation:</strong></p>
 
<ul>
	<li>There is no string in strs that can be rearranged to form <code>&quot;bat&quot;</code>.</li>
	<li>The strings <code>&quot;nat&quot;</code> and <code>&quot;tan&quot;</code> are anagrams as they can be rearranged to form each other.</li>
	<li>The strings <code>&quot;ate&quot;</code>, <code>&quot;eat&quot;</code>, and <code>&quot;tea&quot;</code> are anagrams as they can be rearranged to form each other.</li>
</ul>
</div>
 
<p><strong class="example">Example 2:</strong></p>
 
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">strs = [&quot;&quot;]</span></p>
 
<p><strong>Output:</strong> <span class="example-io">[[&quot;&quot;]]</span></p>
</div>
 
<p><strong class="example">Example 3:</strong></p>
 
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">strs = [&quot;a&quot;]</span></p>
 
<p><strong>Output:</strong> <span class="example-io">[[&quot;a&quot;]]</span></p>
</div>
 
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
 
<ul>
	<li><code>1 &lt;= strs.length &lt;= 10<sup>4</sup></code></li>
	<li><code>0 &lt;= strs[i].length &lt;= 100</code></li>
	<li><code>strs[i]</code> consists of lowercase English letters.</li>
</ul>
 
 
 
---
 
[submissions](https://leetcode.com/problems/group-anagrams/submissions/) | [solutions](https://leetcode.com/problems/group-anagrams/solutions/)
 
 
tab: 中文
 
<p>给你一个字符串数组,请你将 <span data-keyword="anagram">字母异位词</span> 组合在一起。可以按任意顺序返回结果列表。</p>
 
<p>&nbsp;</p>
 
<p><strong>示例 1:</strong></p>
 
<div class="example-block">
<p><strong>输入:</strong> strs = ["eat", "tea", "tan", "ate", "nat", "bat"]</p>
 
<p><strong>输出: </strong>[["bat"],["nat","tan"],["ate","eat","tea"]]</p>
 
<p><strong>解释:</strong></p>
 
<ul>
	<li>在 strs 中没有字符串可以通过重新排列来形成 <code>"bat"</code>。</li>
	<li>字符串 <code>"nat"</code> 和 <code>"tan"</code> 是字母异位词,因为它们可以重新排列以形成彼此。</li>
	<li>字符串 <code>"ate"</code>&nbsp;,<code>"eat"</code>&nbsp;和 <code>"tea"</code> 是字母异位词,因为它们可以重新排列以形成彼此。</li>
</ul>
</div>
 
<p><strong>示例 2:</strong></p>
 
<div class="example-block">
<p><strong>输入:</strong> strs = [""]</p>
 
<p><strong>输出: </strong>[[""]]</p>
</div>
 
<p><strong>示例 3:</strong></p>
 
<div class="example-block">
<p><strong>输入:</strong> strs = ["a"]</p>
 
<p><strong>输出: </strong>[["a"]]</p>
</div>
 
<p>&nbsp;</p>
 
<p><strong>提示:</strong></p>
 
<ul>
	<li><code>1 &lt;= strs.length &lt;= 10<sup>4</sup></code></li>
	<li><code>0 &lt;= strs[i].length &lt;= 100</code></li>
	<li><code>strs[i]</code>&nbsp;仅包含小写字母</li>
</ul>
 
 
 
---
 
[提交记录](https://leetcode.cn/problems/group-anagrams/submissions/) | [题解](https://leetcode.cn/problems/group-anagrams/solution/)
 
 

Solutions & Notes

properties:
  note.updated:
    displayName: Last Updated
  note.relative_links:
    displayName: Related Links
  note.desc:
    displayName: Description
  note.grade:
    displayName: Rating
  note.program_language:
    displayName: Language
  note.time_complexity:
    displayName: TC
  note.space_complexity:
    displayName: SC
views:
  - type: table
    name: Solutions & Notes
    filters:
      and:
        - file.hasLink(this.file)
        - file.tags.containsAny("leetcode/solution", "leetcode/note")
    order:
      - file.name
      - desc
      - program_language
      - time_complexity
      - space_complexity
      - grade
      - relative_links
      - updated
    sort:
      - property: grade
        direction: ASC
      - property: time_complexity
        direction: ASC
      - property: program_language
        direction: ASC
    columnSize:
      file.name: 104
      note.space_complexity: 65
      note.grade: 126
 

Similar Problems

properties:
  note.lcTopics:
    displayName: Topics
  note.lcAcRate:
    displayName: AC Rate
  note.favorites:
    displayName: Favorites
  note.grade:
    displayName: Rating
  note.translatedTitle:
    displayName: Title (CN)
  note.lcDifficulty:
    displayName: Difficulty
views:
  - type: table
    name: Similar Problems
    filters:
      and:
        - file.hasLink(this.file)
        - similarQuestions.contains(this.file)
    order:
      - file.name
      - translatedTitle
      - lcTopics
      - lcDifficulty
      - lcAcRate
      - grade
      - favorites
    sort:
      - property: file.name
        direction: ASC
      - property: lcTopics
        direction: DESC
    columnSize:
      note.translatedTitle: 240
      note.lcTopics: 347
      note.lcAcRate: 75
      note.grade: 122