Skip to content

Commit a1995dc

Browse files
committed
Update Swift/49. Group Anagrams.swift
1 parent 504f268 commit a1995dc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Swift/49. Group Anagrams.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// 49. Group Anagrams
2+
// 164 ms, 58.49%
3+
func groupAnagrams(_ strs: [String]) -> [[String]] {
4+
var dict = [String: [String]]()
5+
strs.forEach {
6+
let s = String($0.sorted())
7+
dict[s] = (dict[s] == nil) ? [$0] : dict[s]! + [$0]
8+
}
9+
return dict.map({$0.value})
10+
}

0 commit comments

Comments
 (0)