We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e70d4cd commit d000b59Copy full SHA for d000b59
leetcode.com/swift/DS_ALGO_PRAC.playground/Contents.swift
@@ -1 +1,16 @@
1
-import Foundation
+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