diff --git "a/docs/10.LeeCode/48.\346\227\213\350\275\254\345\233\276\345\203\217.md" "b/docs/10.LeeCode/48.\346\227\213\350\275\254\345\233\276\345\203\217.md" index c18886d..359b55c 100644 --- "a/docs/10.LeeCode/48.\346\227\213\350\275\254\345\233\276\345\203\217.md" +++ "b/docs/10.LeeCode/48.\346\227\213\350\275\254\345\233\276\345\203\217.md" @@ -60,4 +60,4 @@ Langs: c cpp csharp dart golang java javascript kotlin php python python3 racket

 

<<< @/src/LeeCode/48.旋转图像.js -<<< @/src/LeeCode/48.旋转图像 1.js +<<< @/src/LeeCode/48.旋转图像1.js diff --git "a/docs/10.LeeCode/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.md" "b/docs/10.LeeCode/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.md" new file mode 100644 index 0000000..94dc502 --- /dev/null +++ "b/docs/10.LeeCode/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.md" @@ -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"]' + +

给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。

+ +

字母异位词 是由重新排列源单词的所有字母得到的一个新单词。

+ +

 

+ +

示例 1:

+ +
+输入: strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
+输出: [["bat"],["nat","tan"],["ate","eat","tea"]]
+ +

示例 2:

+ +
+输入: strs = [""]
+输出: [[""]]
+
+ +

示例 3:

+ +
+输入: strs = ["a"]
+输出: [["a"]]
+ +

 

+ +

提示:

+ + + +<<< @/src/LeeCode/49.字母异位词分组.js diff --git "a/src/LeeCode/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.js" "b/src/LeeCode/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.js" new file mode 100644 index 0000000..14b91bb --- /dev/null +++ "b/src/LeeCode/49.\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215\345\210\206\347\273\204.js" @@ -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