Unverified Commit d9c4e27e authored by ASAHI OCEAN's avatar ASAHI OCEAN Committed by GitHub
Browse files

Merge pull request #229 from asahiocean/develop

49. Group Anagrams
parents 3e8d2a29 988b6208
import Foundation
// 49. Group Anagrams
// https://leetcode.com/problems/group-anagrams/
class Solution {
func groupAnagrams(_ strs: [String]) -> [[String]] {
var res = [[String]](), dict = [[Character]:[String]]()
strs.forEach {
let t = $0.sorted()
dict[t] == nil ? (dict[t] = [$0]) : (dict[t]?.append($0))
}
dict.forEach{ res.append($1) }
return res
}
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment