-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bae9ec5
commit 7768562
Showing
3 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
title: 49.字母异位词分组 | ||
date: 2024-03-23 | ||
lang: 'zh-CN' | ||
sidebar: 'auto' | ||
categories: | ||
- LeeCode | ||
tags: | ||
location: HangZhou | ||
--- | ||
|
||
# Heading | ||
|
||
[[toc]] | ||
|
||
[49.字母异位词分组](https://leetcode.cn/problems/group-anagrams/description/) | ||
|
||
Tags: algorithms amazon bloomberg facebook uber yelp hash-table string | ||
|
||
Langs: c cpp csharp dart elixir erlang golang java javascript kotlin php python python3 racket ruby rust scala swift typescript | ||
|
||
- algorithms | ||
- Medium (67.90%) | ||
- Likes: 1857 | ||
- Dislikes: - | ||
- Total Accepted: 657.2K | ||
- Total Submissions: 967.4K | ||
- Testcase Example: '["eat","tea","tan","ate","nat","bat"]' | ||
|
||
<p>给你一个字符串数组,请你将 <strong>字母异位词</strong> 组合在一起。可以按任意顺序返回结果列表。</p> | ||
|
||
<p><strong>字母异位词</strong> 是由重新排列源单词的所有字母得到的一个新单词。</p> | ||
|
||
<p> </p> | ||
|
||
<p><strong>示例 1:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong> strs = <code>["eat", "tea", "tan", "ate", "nat", "bat"]</code> | ||
<strong>输出: </strong>[["bat"],["nat","tan"],["ate","eat","tea"]]</pre> | ||
|
||
<p><strong>示例 2:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong> strs = <code>[""]</code> | ||
<strong>输出: </strong>[[""]] | ||
</pre> | ||
|
||
<p><strong>示例 3:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong> strs = <code>["a"]</code> | ||
<strong>输出: </strong>[["a"]]</pre> | ||
|
||
<p> </p> | ||
|
||
<p><strong>提示:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= strs.length <= 10<sup>4</sup></code></li> | ||
<li><code>0 <= strs[i].length <= 100</code></li> | ||
<li><code>strs[i]</code> 仅包含小写字母</li> | ||
</ul> | ||
|
||
<<< @/src/LeeCode/49.字母异位词分组.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* @lc app=leetcode.cn id=49 lang=javascript | ||
* | ||
* [49] 字母异位词分组 | ||
*/ | ||
|
||
// @lc code=start | ||
/** | ||
* @param {string[]} strs | ||
* @return {string[][]} | ||
*/ | ||
var groupAnagrams = function (strs) { | ||
const map = new Map() | ||
|
||
for (let str of strs) { | ||
const key = str.split('').sort().join() | ||
map.set(key, map.has(key) ? [...map.get(key), str] : [str]) | ||
} | ||
|
||
return [...map.values()] | ||
} | ||
// @lc code=end |