diff --git a/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/README.md b/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/README.md index 971e82ee1..af6d83ac1 100644 --- a/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/README.md +++ b/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/README.md @@ -1,28 +1,38 @@ # [893.Groups of Special-Equivalent Strings][title] -> [!WARNING|style:flat] -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) - ## Description +You are given an array of strings of the same length `words`. + +In one **move**, you can swap any two even indexed characters or any two odd indexed characters of a string `words[i]`. + +Two strings `words[i]` and `words[j]` are **special-equivalent** if after any number of moves, `words[i] == words[j]`. + +- For example, `words[i] = "zzxy"` and `words[j] = "xyzz"` are **special-equivalent** because we may make the moves `"zzxy" -> "xzzy" -> "xyzz"`. + +A **group of special-equivalent strings** from `words` is a non-empty subset of words such that: + +- Every pair of strings in the group are special equivalent, and +- The group is the largest size possible (i.e., there is not a string `words[i]` not in the group such that `words[i]` is special-equivalent to every string in the group). + +Return the number of **groups of special-equivalent strings** from `words`. **Example 1:** ``` -Input: a = "11", b = "1" -Output: "100" +Input: words = ["abcd","cdab","cbad","xyzz","zzxy","zzyx"] +Output: 3 +Explanation: +One group is ["abcd", "cdab", "cbad"], since they are all pairwise special equivalent, and none of the other strings is all pairwise special equivalent to these. +The other two groups are ["xyzz", "zzxy"] and ["zzyx"]. +Note that in particular, "zzxy" is not special equivalent to "zzyx". ``` -## 题意 -> ... - -## 题解 +**Example 2:** -### 思路1 -> ... -Groups of Special-Equivalent Strings -```go ``` - +Input: words = ["abc","acb","bac","bca","cab","cba"] +Output: 3 +``` ## 结语 diff --git a/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/Solution.go b/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/Solution.go index d115ccf5e..80797a49f 100644 --- a/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/Solution.go +++ b/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/Solution.go @@ -1,5 +1,17 @@ package Solution -func Solution(x bool) bool { - return x +func Solution(words []string) int { + in := make(map[[2][26]int]int) + for _, word := range words { + k1, k2 := [26]int{}, [26]int{} + for i := range word { + if i&1 == 0 { + k1[word[i]-'a']++ + continue + } + k2[word[i]-'a']++ + } + in[[2][26]int{k1, k2}]++ + } + return len(in) } diff --git a/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/Solution_test.go b/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/Solution_test.go index 14ff50eb4..b45d02e18 100644 --- a/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/Solution_test.go +++ b/leetcode/801-900/0893.Groups-of-Special-Equivalent-Strings/Solution_test.go @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) { // 测试用例 cases := []struct { name string - inputs bool - expect bool + inputs []string + expect int }{ - {"TestCase", true, true}, - {"TestCase", true, true}, - {"TestCase", false, false}, + {"TestCase1", []string{"abcd", "cdab", "cbad", "xyzz", "zzxy", "zzyx"}, 3}, + {"TestCase2", []string{"abc", "acb", "bac", "bca", "cab", "cba"}, 3}, } // 开始测试 @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) { } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }