Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit145b988

Browse files
committed
add: Group Anagrams
1 parentbb0da02 commit145b988

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
2929
|43|[Multiply Strings](https://leetcode.com/problems/multiply-strings/)|[JavaScript](./src/multiply-strings/res.js)|Medium|
3030
|46|[Permutations](https://leetcode.com/problems/permutations/)|[JavaScript](./src/permutations/res.js)|Medium|
3131
|48|[Rotate Image](https://leetcode.com/problems/rotate-image/)|[JavaScript](./src/rotate-image/res.js)|Medium|
32+
|49|[Group Anagrams](https://leetcode.com/problems/anagrams/)|[JavaScript](./src/anagrams/res.js)|Medium|
3233
|54|[Spiral Matrix](https://leetcode.com/problems/spiral-matrix/)|[JavaScript](./src/spiral-matrix/res.js)|Medium|
3334
|66|[Plus One](https://leetcode.com/problems/plus-one/)|[JavaScript](./src/plus-one/res.js)|Easy|
3435
|69|[Sqrt(x)](https://leetcode.com/problems/sqrtx/)|[JavaScript](./src/sqrtx/res.js)|Easy|

‎src/anagrams/res.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* res.js
3+
*@authors Joe Jiang (hijiangtao@gmail.com)
4+
*@date 2017-05-10 22:14:38
5+
*
6+
*@param {string[]} strs
7+
*@return {string[][]}
8+
*/
9+
letgroupAnagrams=function(strs){
10+
letlen=strs.length;
11+
if(!len)return[];
12+
13+
lethashmap=newMap();
14+
for(leti=0;i<len;i++){
15+
lettmparr=strs[i].split('');
16+
tmparr.sort();
17+
tmparr=tmparr.join();
18+
if(!hashmap.has(tmparr)){
19+
hashmap.set(tmparr,[strs[i]]);
20+
}else{
21+
lettmp=hashmap.get(tmparr);
22+
tmp.push(strs[i]);
23+
hashmap.set(tmparr,tmp);
24+
}
25+
}
26+
27+
letres=[];
28+
console.log(hashmap);
29+
for(let[key,value]ofhashmap){
30+
res.push(value);
31+
}
32+
33+
returnres;
34+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp