Skip to content

Commit d000b59

Browse files
author
Partho Biswas
committed
no message
1 parent e70d4cd commit d000b59

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
import Foundation
1+
class Solution {
2+
func groupStrings(_ strings: [String]) -> [[String]] {
3+
var groupMap = [String:[String]]()
4+
strings.forEach { string in
5+
let patttern = getPatternKey(string)
6+
groupMap[patttern, default: [String]()] += [string]
7+
}
8+
return Array(groupMap.values)
9+
}
10+
11+
func getPatternKey(_ string: String) -> String {
12+
let asciiValues = string.unicodeScalars.map({ Int($0.value) })
13+
let diffValue = asciiValues.map({ (26 + $0 - asciiValues[0]) % 26 })
14+
return diffValue.reduce("", { $0 + " \($1)" })
15+
}
16+
}

0 commit comments

Comments
 (0)