We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difficulty: 中等
Related Topics: 数组, 哈希表, 字符串, 排序
给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。
字母异位词 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。
示例 1:
输入: strs = ["eat", "tea", "tan", "ate", "nat", "bat"] 输出: [["bat"],["nat","tan"],["ate","eat","tea"]]
示例 2:
输入: strs = [""] 输出: [[""]]
示例 3:
输入: strs = ["a"] 输出: [["a"]]
提示:
0 <= strs[i].length <= 100
strs[i]
Language: JavaScript
/** * @param {string[]} strs * @return {string[][]} */ var groupAnagrams = function(strs) { const map = new Map() for (let str of strs) { let array = Array.from(str) array.sort() let key = array.toString() let list = map.get(key) ? map.get(key) : [] list.push(str) map.set(key, list) } return Array.from(map.values()) };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
49. 字母异位词分组
Description
Difficulty: 中等
Related Topics: 数组, 哈希表, 字符串, 排序
给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。
字母异位词 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。
示例 1:
示例 2:
示例 3:
提示:
0 <= strs[i].length <= 100
strs[i]
仅包含小写字母Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: